Accessing SQL Server on NetBeans using JDBC, Part III: Troubleshooting
Java, NetBeans, Programming February 23rd, 2008This post is the last part which gathers common problems along with solutions about accessing SQL Server using JDBC on NetBeans. By defer posting this a few months, I found many problems that may occur from many people and also solutions. So this post will benefit people who want to develop application to connect a SQL Server using JDBC and have problem with it.
There are 3 parts:
- Part I : Create a connection
This part which you’re reading shows about how to establish a connection between NetBeans and SQL Server. In this example, I use SQL Server 2000 SP4 and NetBeans IDE 5.5 - Part II : Perform SQL Operations
This part show how to perform some basic operations from NetBeans with SQL Server. For instance, send querys as SELECT, INSERT, UPDATE to the database. - Part III: Troubleshooting
The last part is about problems and how to fix them.
Troubleshooting index
- Missing the JDBC library
- Mistype the connection string
- The TCP/IP connection to the host has failed
- Login failed for user ’sa’
- This driver is not configured for integrated authentication
-
Missing the JDBC library
Problem
You received this error message while compile code in part I.
Class Not Found Exception: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
![]()
Cause
This problem may have many causes as the following:
- The JDBC library file is not loaded properly. You may not have add the library file “sqljdbc.jar” to the project.
- You haven’t import the needed library to the project
Solution
- Add the appropriate library to the project. Refer to part I: create a connection.

- You need to add following code at the top of thesource code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

Or you can
import java.sql.*;
Mistype the connection string
Problem
You received this error message while compile code in part I.
SQL Exception: java.sql.SQLException: No suitable driver found for jdbc:sqlserver:\\bkksql2005:1433;databaseName=AdventureWorks;user=sa;password=password;
Cause
You may have typed your connection string incorrectly so the JDBC driver couldn’t understand.
Solution
Recheck your connection string format. The format for SQL authentication mode should be
“jdbc:sqlserver://serverName:portNumber;databaseName=DatabaseName;user=UserName;password=Password;” where
- serverName is the name of the SQL Server
- (Optional) portNumber is the TCP port of SQL Server. Default port is 1433.
- (Optional) DatabaseName is the database name on SQL Server.
- UserName and Password are username and password for login to SQL Server. This user must be SQL Server authentication mode.
The format for Windows authentication mode should be
“jdbc:sqlserver://serverName:portNumber;databaseName=DatabaseName;integratedSecurity=true;” where
- serverName is the name of the SQL Server
- (Optional) portNumber is the TCP port of SQL Server. Default port is 1433.
- (Optional) DatabaseName is the database name on SQL Server.
Note: Database name is an optional. For more complex connection string, refer to MSDN – Building the Connection URL at Microsoft.
In this example, I mistype “jdbc:sqlserver://…” to “jdbc:sqlserver:\\…“.
The TCP/IP connection to the host has failed
Problem
You received this error message while compile code in part I.
SQL Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host has failed. java.net.ConnectException: Connection refused: connect
Cause
You try to connect to a SQL Server which has not SQL Server service running or the service refuse to accept remote connections.
Solution
- Recheck your connection string that you have type server name and port correctly or not.
- Check that SQL Server is running.
- If SQL Server is on remote host, try to check that you have allow remote connections on the server. To enable remote connections on SQL Server, try visit Enable remote connection to SQL Server 2005 Express.
- Check firewall which may block the connection from client to server.
Login failed for user ’sa’
Problem
You received this error message while compile code in part I.
SQL Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user ’sa’.
Cause
This error message states clearly that you have provide wrong username or password that connect to SQL Server.
Solution
Recheck username and password again.
This driver is not configured for integrated authentication
Problem
You need to use Windows authentication mode by using ‘integratedSecurity=true’ instead of specify username and password in the connection string but receive this error message:
SQL Exception: com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication.
Feb 8, 2008 11:28:55 AM com.microsoft.sqlserver.jdbc.AuthenticationJNI
WARNING: Failed to load the sqljdbc_auth.dll
Cause
You need to add ’sqljdbc_auth.dll’ to the system path. This file can be found in Microsoft SQL Server JDBC Driver. It resides in sqljdbc_1.1\enu\auth\x86 depends on your JDBC driver and system platform (x86 or x64).
Solution
Copy ’sqljdbc_auth.dll’ to C:\Windows\System32
or
You can set the java.library.path to the directory where ’sqljdbc_auth.dll’ is.

Note: If the path contains any spaces or special characters, you have to use double quotes “” around the value (ex. “your directory”).
Related post
- Accessing SQL Server on NetBeans using JDBC, Part I: Create a connection Introduction This tutorial show you how to use NetBeans to connect SQL Server (2000 and 2005) by using Microsoft SQL...
- Accessing SQL Server on NetBeans using JDBC, Part II: Perform SQL Operations From Part I, I have only established a connection with local SQL Server. Next I’ll show how to retrieve and...
- Accessing MySQL on NetBeans using JDBC, Part I: Create a connection Introduction This tutorial show you how to use NetBeans to connect MySQL by using MySQL Connector/J, MySQL AB’s JDBC Driver...
- Accessing MS Access 2007 on NetBeans 6.5 using JDBC, Part 3: Create a Connection This article is one of the series of Accessing MS Access 2007 on NetBeans 6.5 using JDBC. You can see...
- Accessing MySQL on NetBeans using JDBC, Part II: Perform SQL Operations From Part I, I have only established a connection with local MySQL. Next I’ll show how to retrieve and modify...
Related posts:





October 15th, 2008 at 3:18 am
it proved to be realy healpful, my problem is that im working in netbeans Desktop Application, i hav made a form, and behind the actionListener of it, i wana create connection as wel as perform operations ie; Save, Delete etc…
now wat things i hav to do more, how to map the textfields to database?
plzzz kindly let mekno ASAP…
October 15th, 2008 at 9:57 pm
Have you read Accessing SQL Server on NetBeans using JDBC, Part II: Perform SQL Operations?
I think it can be applied to what you want.
November 26th, 2008 at 10:36 am
i’m using sql server 2000, OS winXP, Netbeans 6.1,
n try the code above to connect Netbeans to Sql n get error :
SQL Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host has failed. java.net.ConnectException: Connection refused: connect
BUILD SUCCESSFUL (total time: 1 second)
i try to telnet port 1433, but result connection failed, although my Sql Service is running… can any one help my problem? i already turn off my Firewall.. n i already check thats my sql active port is 1433.. why i can;t telnet port 1433?
Thanks
November 26th, 2008 at 9:46 pm
If you can’t telnet to SQL Server on certain port. It may cause from these issues:
- The firewall between your computer and SQL Server has blocked telnet protocol.
- The SQL Server is running on this port.
- The SQL Server service is not running.
So you need to check if the firewall on SQL Server or on your network are blocking the telnet protocol or not. You can try to telnet on SQL Server itself to avoid firewall on the network.
Next, if you can telnet but still unable to connect in java. Try to remove the port number in the connection string (You can omit the default port).
January 7th, 2009 at 2:14 am
Thank you
i am finding soluction this problem your meterial is very nice that is help full me
thank you..
January 15th, 2009 at 12:31 pm
my problems are still unsolved, or assuming that it works in your PC, can i have the spesification of the PC such as what is the OS, what is the version of SQL Server (2000 or 2005), and other requirements. So i can try from zero. Thanks alot.
January 15th, 2009 at 9:09 pm
Hi, Alex
About environment in the tutorial: Windows XP SP2 with NetBeans 5.5 and SQL Server 2000 SP4 on the same computer.
I suggest the best way is to develop on the same computer first (connect to SQL Server on the local machine).
May 8th, 2009 at 2:00 pm
Hi,
Thanks for the nice post. My issue is I can create connection to MS SQL Server 2005 through the runtime window in netbeans 6.5,1, but it doesn’t show any tables nor does running queries help. I need to use hibernate in my project and that requires this connection to work properly. Am I missing something? Thanks
May 12th, 2009 at 9:37 am
Hi, Vikash
Is there any error message when you established a connection to the SQL Server?
May 13th, 2009 at 12:05 am
I am getting the following error:
The TCP/IP connection to the host has failed.
java.net.SocketException: Malformed reply from SOCKS server
My connection string is:
(0.0.0.0 = is the fake ip address to the server for this post)
(***** = is the fake password for this post)
jdbc:sqlserver://0.0.0.0:1433;databaseName=ITAssetsDB;user=sa;password=*****;
May 13th, 2009 at 12:15 am
Ok, in Netbeans I have a proxy configured and it could not connect through that proxy. Once I turned the proxy off, it connected just fine.
May 19th, 2009 at 1:48 am
thank you for this very useful content. everything worked fine after doing excatly the way you meant.
Kind regards,
Serhat from TRNC
October 12th, 2009 at 9:48 pm
hi Linglom,
i’m using this driver “Microsoft SQL Server JDBC Driver 2.0″ to connect to SQL Server 2000 from Netbean 6.7.1
i got this error
“Unable to add connection. Cannot establish a connection to
jdbc:sqlserver://localhost:1433;databaseName=Northwind using
com.microsoft.sqlserver.jdbc.SQLServerDriver (The TCP/IP connection
to the host localhost, port 1433 has failed. Error: “connect timed out.
Verify the connaction propoerties, check that an instance of SQL
Server is running on the host and accepting TCP/IP connections
at the port, and that no firewall is blocking TCP connections to the port.”.).”
though that i’ve verifed from Server Network Utility that the TCP/IP protocol is enabled and is listening on port 1433.
i can connect to the server through query analyzer though. i wonder what’s wrong?
Thank you.
October 13th, 2009 at 11:53 am
Hi, Thesti
The error message states that it couldn’t connect to the SQL Server so there must be something wrong. I suggest you try to telnet to port 1433 to re-verify if the SQL Server is accepting request or not.
If telnet can connect, then try to change hostname on the connection string to an ip address of your computer.
If it still doesn’t solve the problem, can you show your source code?
March 9th, 2010 at 3:56 am
Hi thesti,
I had the same problem, that made me waste an entire day looking for a solution.
The problem, in my case, was the instance name, using a named instance, like this
jdbc:sqlserver://SERVERNAME\INSTANCE:1433;databaseName=TESTDB
I changed my instalation, so the server isn’t named, and just accept a connection in the form:
jdbc:sqlserver://SERVERNAME:1433;databaseName=TESTDB
and I got the connection working.