Sunday, February 19, 2012

Connecting JDBC with SQL Server, error establishing socket

I have tried everything..I cant get Java to connect to my sql
server...
heres the code I altered provided my microsoft to test this connection:
import java.sql.*;
class test {
public static void main(String args[]) {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLSer verDriver").newInstance();
Connection conn = DriverManager.getConnection(
"jdbc:datadirect:sqlserver://dbserver:1433;DatabaseName=sample",
"sa", "");
conn.close();
System.out.println("ok");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Heres the error messages:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error
establis
hing socket.
at com.microsoft.jdbc.base.BaseExceptions.createExcep tion(Unknown
Source
)
at com.microsoft.jdbc.base.BaseExceptions.getExceptio n(Unknown
Source)
at com.microsoft.jdbc.base.BaseExceptions.getExceptio n(Unknown
Source)
at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<in it>(Unknown
Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplConnecti on.open(Unknown
Sou
rce)
at
com.microsoft.jdbc.base.BaseConnection.getNewImplC onnection(Unknown S
ource)
at com.microsoft.jdbc.base.BaseConnection.open(Unknow n Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager .java:512)
at java.sql.DriverManager.getConnection(DriverManager .java:171)
at test.main(test.java:12)
thanks
It appears that you do not have access to your db server machine.
try ping command for the IP address.
This has to do with the network settings.
I use MSSQLServer driver and It seems that my DB-URL is different.
DRIVER=com.microsoft.jdbc.sqlserver.SQLServerDrive r
URL=jdbc:microsoft:sqlserver://localhost:1433;SelectMethod=cursor
this works fine.
Message posted via http://www.sqlmonster.com

No comments:

Post a Comment