This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Exception in thread "main" java.sql.SQLException: [Microsoft][SQLServer 2000 Driver f" Watch "Exception in thread "main" java.sql.SQLException: [Microsoft][SQLServer 2000 Driver f" New topic
Author

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

Kamal Ahmed
Ranch Hand

Joined: Feb 15, 2005
Posts: 91
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

Kamal,
Do you have a firewall blocking the port? Can you connect to SQL Server regularly (without going through Java) ?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.


[My Blog]
All roads lead to JavaRanch
 
Consider Paul's rocket mass heater.
 
subject: Exception in thread "main" java.sql.SQLException: [Microsoft][SQLServer 2000 Driver f
 
Similar Threads
Where can i get JDBC driver for MS Sql Server
How to Configure JBoss for MSSql type4 Driver
JDBC connection to MS SQL Server .. HELP
Best JDBC drivers?
JSP, SQLServer2000 and TomCat