No suitable driver found for jdbc sqlserver

Я получаю это исключение, когда пытаюсь запустить эту программу. Это один из примеров Microsoft. Я добавил sqljdbc4.jar в classpath в netbeans для компиляции и запуска через свойства проекта. Я также проверил, что класс можно найти, используя приведенный ниже оператор импорта — во время компиляции не возникает ошибки, поэтому он должен найти банку.

Может ли это быть связано с dll или некоторой sql-dll, ссылающейся на sqldbc4.jar?

Это точное исключение, а ниже — точный код, за исключением пароля.

I’m getting this exception when I try to run this program. It’s one of the Microsoft examples. I’ve added the sqljdbc4.jar to the classpath in netbeans for both compile and Run, via the project properties. I also tested that the class could be found by using an import statement below — no error during compile, so it must be finding the jar.

Could it be related to a dll or some sql dll that the sqldbc4.jar references?

This is the exact exception, and below is the exact code, except for password.

java.sql.SQLException: No suitable driver found for
There are two ways to connect Microsoft SQL Server from Java program, either by using Microsoft’s official JDBC driver ( sqljdbc4.jar ), or by using jTDS driver ( jtds.jar ). This error comes when your supplied database URL d >jtds.jar, makes a mistake while using sqljdbc4.jar by adding "microsoft" in JDBC URL. That makes URL inval >"java.sql.SQLException: No suitable driver : sqljdbc4.jar" error.

For Example in JTDS, the JDBC URL format is

and while using Microsoft’s JDBC driver, the URL format is :

where jdbc:sqlserver string i s mandatory because it’s used to >serverName , instanceName , and portNumber is optional. If you don’t provide serverName then SQL server will look into properties collection, if an instance is not specified then JDBC will connect to default instance and if the port number is not specified then it will connect to default SQL Server port number 1433.

Читайте также:  Базовый mbr жесткий диск

Common reasons of "No suitable driver found" Error

Let’s see some of the most common reasons for getting java.sql.SQLException: No suitable driver found for jdbc: error while connecting to SQL SERVER 2008, 2012 and 2014.

1) You are using JDBC URL format for jTDS driver (jdbc:jtds://localhost:1434";) but deployed sqljdbc4.jar in CLASSPATH. In this case, you will get following error :

In order to solve this error, just add jtds.jar in >jtds.jar , you can download it from here. Alternatively, you can also add following Maven dependency, if you are using Maven to build your project :

If you already have this JAR file in your CLASSPATH but still getting above error, maybe it’s time to revisit your CLASSPATH settings. See Core Java, Volume II—Advanced Features by Cay S. Horstmann to learn more about JDBC drivers and URL.

2) Many junior programmer’s make mistake of including "microsoft" in JDBC URL for SQL SERVER like "jdbc:microsoft:sqlserver://localhost:1433" , while using sqljdbc4.jar file to connect MSSQL database. This will result in the following exception :

In order to fix this error just remove microsoft from URL. Correct JDBC URL format to connect SQL SERVER is "jdbc:sqlserver://localhost:1433";. No need to worry about >SQLJDBC4.jar is not present then it will give you a different error, something like java.lang.ClassNotFoundException: .

3) The third common reason of No suitable driver found the error is spelling mistake. For example, if you are using jTDS driver to connect SQL SERVER 2008 database but given JDBC URL like "jdbc:jdts://localhost:1434". It’s very difficult to spot that instead of writing "j t ds" , you have written " j d ts" . I have seen this error many times, only to realize after spending hours checking CLASSPATH settings. You will be greeted with following error :

Читайте также:  Asus rt n12 режим моста

Solving this error is easy, just correct the spelling in JDBC URL and you are done.

Ссылка на основную публикацию