Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception in thread "main" java.sql.SQLException: [Microsoft][SQLServer 2000 Driver f

 
Kamal Ahmed
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using the following java file to get connected to an instance of MSSQL server on my desktop, but getting an exception, any ideas ?


import java.sql.Connection;

import java.sql.DatabaseMetaData;

import java.sql.DriverManager;



/**

* Microsoft SQL Server JDBC test program

*

* http://msdn.microsoft.com/downloads/default.asp?URL=/downloads/sample.asp?url=/MSDN-FILES/027/001/779/msdncompositedoc.xml

* http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q313100&

*/

public class Test {

static Test test;

public Test() throws Exception {



// Get connection

DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());



Connection connection = DriverManager.getConnection(

"jdbc:microsoft:sqlserver://kdesktop_xp:1433", "sa", "123qweasd");



if (connection != null) {



System.out.println();

System.out.println("Successfully connected");

System.out.println();



// Meta data

DatabaseMetaData meta = connection.getMetaData();



System.out.println("Driver Information");

System.out.println("\tDriver Name: "+ meta.getDriverName());

System.out.println("\tDriver Version: "+ meta.getDriverVersion());

System.out.println("\nDatabase Information ");

System.out.println("\tDatabase Name: "+ meta.getDatabaseProductName());

System.out.println("\tDatabase Version: "+ meta.getDatabaseProductVersion());



// Select some data

/*

Statement select = connection.createStatement();

ResultSet result = select.executeQuery("SELECT msisdn FROM member");



while (result.next()) {



System.out.println(result.getString(1));

}

*/

}

} // Test



public static void main (String args[]) throws Exception {





test = new Test();

}



}



Exception:



Exception in thread "main" java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.

at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)

at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)

at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)

at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)

at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)

at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)

at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)

at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)

at java.sql.DriverManager.getConnection(DriverManager.java:525)

at java.sql.DriverManager.getConnection(DriverManager.java:171)

at Test.<init>(Test.java:21)

at Test.main(Test.java:59)

i am using eclipse 3.1, and have included :
msbase.jar
mssqlserver.jar
msutil.jar

in the project.

Thanks in advance.

-Kamal.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kamal,
Do you have a firewall blocking the port? Can you connect to SQL Server regularly (without going through Java) ?
 
Maximilian Xavier Stocker
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The standard SQL server connection error (socket based) checklist includes...

- is the server where you think it is (have you specified the right host)
- is there a firewall anywhere that is eating this (previously suggested but check for firewall problems on all of the client, the server and any network device in between)
- is SQL Server set up to listen for TCP connections? (by default SQL server listens for named pipe connections only and these will largely not work and I am pretty sure never work with that driver)
- is SQL Server set up to listen on the default port or another one that you need to specify?

Please note that if you need to enable TCP connection mode you need to restart the service. This isn't entirely clear in the docs but for versions I have worked with if you don't restart then that change does not actually take effect.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've experienced problems with Microsoft JDBC driver for Sql Server.
A real pain in the **** it was.
And as mentioned above, it won't work with named pipes.

If you still experience problems, try jTDS JDBC Driver.
This one solved all my problems.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic