hi,
The example below(Reference:http://www.java-tips.org/other-api-tips/jdbc/how-to-connect-microsoft-sql-server-using-jdbc.html) shows how to make a connection to Microsoft SQL Server 2000 using jTDS driver:
import java.sql.*;
public class testConnection
{
public static void main(String[] args)
{
DB db = new DB();
db.dbConnect(
"jdbc:jtds:sqlserver://localhost:1433/tempdb","sa","");
}
}
class DB
{
public DB() {}
public voidn dbConnect(String db_connect_string,
String db_userid, String db_password)
{
try
{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection conn = DriverManager.getConnection(
db_connect_string, db_userid, db_password);
System.out.println("connected");
}
catch (Exception e)
{
e.printStackTrace();
}
}
};
When I try to connect to the database engine on my local machine with the connect string that has a port number and instance name as:
jdbc:jtds:sqlserver://dtw117313d1:2936/pubs_sql2000;instance=sql2005
I do not get an error. i'm able to connect.
But, when I try to make a remote connection with the connect string that has the port number and the instance name, the
connection fails.
The connect string when I try to connect to a remote database engine is:
jdbc:jtds:sqlserver://dtw101290d1:1533/OmigaTestScriptInstance;instance=sql2005
The error I get is :
java.sql.SQLException: Unable to get information from SQL Server: dtw101290d1.
at net.sourceforge.jtds.jdbc.MSSqlServerInfo.<init>(MSSqlServerInfo.java:91)
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:263)
at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3.java:50)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:178)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at testJDBC.DB.dbConnect(DB.java:16)
at testJDBC.testConnection.main(testConnection.java:8)
From the error it seems to me that the connection string that I pass is not correct. But, i am not sure what is wrong with the connect string that I'm passing.
Please help.