File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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

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

Kamal Ahmed
Ranch Hand

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





public class Test {

static Test test;

public Test() throws Exception {

// Get connection


Connection connection = DriverManager.getConnection(

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

if (connection != null) {


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


// 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 ( {





} // Test

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

test = new Test();




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

at Source)

at Source)

at Source)

at<init>(Unknown Source)

at Source)

at Source)

at Source)

at Source)

at java.sql.DriverManager.getConnection(

at java.sql.DriverManager.getConnection(

at Test.<init>(

at Test.main(

i am using eclipse 3.1, and have included :

in the project.

Thanks in advance.

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33111

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

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, 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é

Joined: Nov 24, 2005
Posts: 14688

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
I agree. Here's the link:
subject: Exception in thread "main" java.sql.SQLException: [Microsoft][SQLServer 2000 Driver f
It's not a secret anymore!