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 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 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 MS Access 2007 on NetBeans 6.5 using JDBC, Part 4: Perform SQL Operations This article is one of the series of Accessing Access 2007 on NetBeans 6.5 using JDBC. You can see the...
- 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...
- Accessing MS Access 2007 on NetBeans 6.5 using JDBC, Part 1: Introduction Introduction Here comes again, a tutorial about accessing database on NetBeans. In 2007, I wrote two tutorials which are accessing...
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.
June 23rd, 2010 at 4:56 pm
it is really good to see problems and solutions . Really it helps us too much and i m very thankfull to u for providing us such news
July 6th, 2010 at 5:14 pm
SQL Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user ‘THANKGOD-PC/THANKGOD’ This exactly the problem i have
November 11th, 2010 at 4:18 pm
SQL Exception: com.microsoft.sqlserver.jdbc.SQLServerException
November 12th, 2010 at 1:44 pm
Can someone please hellp me,
This is my connection string.
String connectionUrl = “jdbc:sqlserver://” + IP + “; databaseName=” + Database + “; User=” + user + “; Password=” + password + “;”;
the IP,Database,user and password are strings.
when i run the class i got this error
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host has failed. java.net.SocketException: Malformed reply from SOCKS server
Can someone PLEASE HELP ME.
November 12th, 2010 at 5:04 pm
Hello Sir,
I had made a project in netbeans with DB SQL server2005 . My problem is that when i m running the project through netbeans it is running successfully and also it is successfully connected with the DB. But ,when i run the jar file trough cmd it is showing the following error:
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host has failed.
Please help me out , so i can deliver my project to the client.
Thanks.
January 16th, 2011 at 11:43 pm
Nice. Very useful!
January 17th, 2011 at 1:11 pm
Hello All,
My problem is solved. The above error comes due to the package problem. Just i had to move one image from one package to another.
February 15th, 2011 at 11:09 am
i am getting the error as communication link failure. will u pls tell me how to solve this??
February 23rd, 2011 at 11:17 am
Hi,
I’m using Netbeans 6.8 and SQL server 2005, sqljdbc driver.
I’m trying to insert form elements into databae using javascript as well as php. My problem is that whenever i try to run the program it opens up a jsp page. Can someone help me solve this??
March 5th, 2011 at 4:57 am
Really helpfull. At least I was able to connect to SQL Express 2008.
March 15th, 2011 at 4:41 pm
Thank you for posting these information.
I was able to configure even I am using SQL 2005.
More power.
May 23rd, 2011 at 4:20 pm
Thanx it helped!!
June 18th, 2011 at 5:22 pm
I have following error when user connection with sql server 2005
init:
deps-jar:
Compiling 1 source file to C:\Users\Archana\Documents\NetBeansProjects\TestSQL\build\classes
compile:
run:
SQL Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The connection string contains a badly formed name or value.
BUILD SUCCESSFUL (total time: 0 seconds)
July 29th, 2011 at 2:36 am
i have following error
Jul 29, 2011 1:03:43 AM com.microsoft.sqlserver.jdbc.SQLServerConnection
SEVERE: Java Runtime Environment (JRE) version 1.6 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0.
Exception in thread “main” java.lang.UnsupportedOperationException: Java Runtime Environment (JRE) version 1.6 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0.
at com.microsoft.sqlserver.jdbc.SQLServerConnection.(SQLServerConnection.java:238)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:207)
at database.Database.main(Database.java:36)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)