| Accessing SQL Server on NetBeans using JDBC, Part III: Troubleshooting |
This 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
- 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
- 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
- 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.
- 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.
-
The TCP/IP connection to the host has failed
- 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’
-
This driver is not configured for integrated authentication
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:
Solution
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
The format for Windows authentication mode should be
“jdbc:sqlserver://serverName:portNumber;databaseName=DatabaseName;integratedSecurity=true;” where
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:\\…“.
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
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.
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”).


























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.