This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Establishing JDBC Connection Using Port Ips

 
nivas khan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir,
i have a Ms SQL server DB on my desktop.
And i want to connect to it using the methods described below.
but i am unable to connect.Can u help me with the code..
I have a win NT OS.What is the Ip adress to be given.
Nivas

String dataPath = "jdbc dbc RIVER={SQL Server}:SERVER={ip_address}:?DATABASE=MY_DBASE";
where is the value of the port you want to use...like 1433 or something like that.
Use the user id and password like this:
Connection conn = DriverManagner.getConnection( dataPath, USER_NAME, my_pass);
 
DAYANAND BURAMSHETTY
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

public Connection getConnection() throws SQLException
{
System.out.println("ConnectionTest....................\n");
try{
Class.forName("weblogic.jdbc.mssqlserver4.Driver").newInstance();
} catch (ClassNotFoundException cnfe) {
throw new SQLException(cnfe.getMessage());
} catch (IllegalAccessException iae) {
throw new SQLException(iae.getMessage());
} catch (InstantiationException ie) {
throw new SQLException(ie.getMessage());
}
Connection con = null;
Properties props = new Properties();
props.put("user","scott");
props.put("password","tiger");
try {
con = DriverManager.getConnection("jdbc:weblogic:mssqlserver4:MY_DBASE@ip_address:1433",props);
return con;
} catch (Exception e) {
System.out.println("Exception :::"+e.getMessage());
throw new SQLException (e.getMessage());
}
}

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic