java.sql.SQLException: No suitable driver constitute for
There are 2 ways to connect Microsoft SQL Server from Java program, either past times using Microsoft's official JDBC driver (sqljdbc4.jar), or past times using jTDS driver (jtds.jar). This error comes when your supplied database URL didn't stand upwards for alongside the JDBC driver introduce inward the CLASSPATH. Many programmers who normally usage jtds.jar, makes a error land using sqljdbc4.jar past times adding "microsoft" inward JDBC URL. That makes URL invalid together with JDBC API throws "java.sql.SQLException: No suitable driver : sqljdbc4.jar" error.
For Example inward JTDS, the JDBC URL format is
jdbc:jtds:://[:][/][;=[;...]]
together with land using Microsoft's JDBC driver, the URL format is :
jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]]
where jdbc:sqlserver string is mandatory because it's used to position JDBC drive. It is too known every bit sub-protocol. All other parameters e.g. serverName, instanceName, together with portNumber is optional. If y'all don't render serverName thence SQL server volition hold back into properties collection, if an instance is non specified thence JDBC volition connect to default instance together with if the port release is non specified thence it volition connect to default SQL Server port release 1433.
1) You are using JDBC URL format for jTDS driver (jdbc:jtds://localhost:1434";) but deployed sqljdbc4.jar inward CLASSPATH. In this case, y'all volition acquire next error :
In social club to solve this error, only add together jtds.jar inward CLASSPATH of your Java application. If y'all don't receive got jtds.jar, y'all tin download it from here. Alternatively, y'all tin too add together next Maven dependency, if y'all are using Maven to create your projection :
If y'all already receive got this JAR file inward your CLASSPATH but withal getting inward a higher house error, mayhap it's fourth dimension to revisit your CLASSPATH settings. See Core Java, Volume II--Advanced Features past times Cay S. Horstmann to larn to a greater extent than almost JDBC drivers together with URL.
2) Many junior programmer's brand error of including "microsoft" in JDBC URL for SQL SERVER similar "jdbc:microsoft:sqlserver://localhost:1433", land using sqljdbc4.jar file to connect MSSQL database. This volition result inward the next exception :
In social club to ready this error only take microsoft from URL. Correct JDBC URL format to connect SQL SERVER is "jdbc:sqlserver://localhost:1433";. No postulate to worry almost CLASSPATH, because if the SQLJDBC4.jar is non introduce thence it volition hand y'all a dissimilar error, something similar java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver.
3) The 3rd mutual argue of No suitable driver constitute the error is spelling mistake. For example, if y'all are using jTDS driver to connect SQL SERVER 2008 database but given JDBC URL similar "jdbc:jdts://localhost:1434". It's real hard to location that instead of writing "jtds", y'all receive got written "jdts". I receive got seen this error many times, exclusively to realize later spending hours checking CLASSPATH settings. You volition survive greeted alongside next error :
Solving this error is easy, only right the spelling inward JDBC URL together with y'all are done.
4) The 4th argue for getting No suitable driver constitute an error land connecting to MSSQL is specifying JDBC URL every bit "jdbc:sqlserver://localhost:1433" but deployed jTDS driver inward application's CLASSPATH. This happens because many developers usage jTDS driver inward the evolution surroundings together with Microsoft JDBC driver (sqljdbc4.jar) inward the production environment.
In social club to solve that error, only take jTDS driver together with add together Microsoft JDBC driver i.e. sqljdbc4.jar inward your project's create path.
That's all almost how to solve java.sql.SQLException: No suitable driver constitute for jdbc: XXX error inward Java. The root crusade of this employment is wrong JDBC URL, to a greater extent than frequently than non the protocol usage is incorrect. This is non only a Microsoft SQL SERVER specific error but tin come upwards land connecting to whatever database e.g. MySQL using JDBC API. You must brand certain that JDBC URL is absolutely right every bit instructed past times driver manual.
Further Resources to Learn JDBC inward Java :
Further Learning
JSP, Servlets together with JDBC for Beginners: Build a Database App
Complete JDBC Programming Part 1 together with 2
Java Platform: Working alongside Databases Using JDBC
There are 2 ways to connect Microsoft SQL Server from Java program, either past times using Microsoft's official JDBC driver (sqljdbc4.jar), or past times using jTDS driver (jtds.jar). This error comes when your supplied database URL didn't stand upwards for alongside the JDBC driver introduce inward the CLASSPATH. Many programmers who normally usage jtds.jar, makes a error land using sqljdbc4.jar past times adding "microsoft" inward JDBC URL. That makes URL invalid together with JDBC API throws "java.sql.SQLException: No suitable driver : sqljdbc4.jar" error.
For Example inward JTDS, the JDBC URL format is
jdbc:jtds:://[:][/][;=[;...]]
together with land using Microsoft's JDBC driver, the URL format is :
jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]]
where jdbc:sqlserver string is mandatory because it's used to position JDBC drive. It is too known every bit sub-protocol. All other parameters e.g. serverName, instanceName, together with portNumber is optional. If y'all don't render serverName thence SQL server volition hold back into properties collection, if an instance is non specified thence JDBC volition connect to default instance together with if the port release is non specified thence it volition connect to default SQL Server port release 1433.
Common reasons of "No suitable driver found" Error
Let's run across roughly of the most mutual reasons for getting java.sql.SQLException: No suitable driver constitute for jdbc: error land connecting to SQL SERVER 2008, 2012 together with 2014.1) You are using JDBC URL format for jTDS driver (jdbc:jtds://localhost:1434";) but deployed sqljdbc4.jar inward CLASSPATH. In this case, y'all volition acquire next error :
java.sql.SQLException: No suitable driver constitute for jdbc:jtds://localhost:1434 at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source)
In social club to solve this error, only add together jtds.jar inward CLASSPATH of your Java application. If y'all don't receive got jtds.jar, y'all tin download it from here. Alternatively, y'all tin too add together next Maven dependency, if y'all are using Maven to create your projection :
<dependency> <groupId>net.sourceforge.jtds</groupId> <artifactId>jtds</artifactId> <version>1.3.1</version> </dependency>
If y'all already receive got this JAR file inward your CLASSPATH but withal getting inward a higher house error, mayhap it's fourth dimension to revisit your CLASSPATH settings. See Core Java, Volume II--Advanced Features past times Cay S. Horstmann to larn to a greater extent than almost JDBC drivers together with URL.
2) Many junior programmer's brand error of including "microsoft" in JDBC URL for SQL SERVER similar "jdbc:microsoft:sqlserver://localhost:1433", land using sqljdbc4.jar file to connect MSSQL database. This volition result inward the next exception :
java.sql.SQLException: No suitable driver constitute for jdbc:microsoft:sqlserver://localhost:1433 at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source)
In social club to ready this error only take microsoft from URL. Correct JDBC URL format to connect SQL SERVER is "jdbc:sqlserver://localhost:1433";. No postulate to worry almost CLASSPATH, because if the SQLJDBC4.jar is non introduce thence it volition hand y'all a dissimilar error, something similar java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver.
3) The 3rd mutual argue of No suitable driver constitute the error is spelling mistake. For example, if y'all are using jTDS driver to connect SQL SERVER 2008 database but given JDBC URL similar "jdbc:jdts://localhost:1434". It's real hard to location that instead of writing "jtds", y'all receive got written "jdts". I receive got seen this error many times, exclusively to realize later spending hours checking CLASSPATH settings. You volition survive greeted alongside next error :
java.sql.SQLException: No suitable driver constitute for jdbc:jdts://localhost:1434 at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source)
Solving this error is easy, only right the spelling inward JDBC URL together with y'all are done.
4) The 4th argue for getting No suitable driver constitute an error land connecting to MSSQL is specifying JDBC URL every bit "jdbc:sqlserver://localhost:1433" but deployed jTDS driver inward application's CLASSPATH. This happens because many developers usage jTDS driver inward the evolution surroundings together with Microsoft JDBC driver (sqljdbc4.jar) inward the production environment.
java.sql.SQLException: No suitable driver constitute for jdbc:sqlserver://localhost:1433 at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source)
In social club to solve that error, only take jTDS driver together with add together Microsoft JDBC driver i.e. sqljdbc4.jar inward your project's create path.
That's all almost how to solve java.sql.SQLException: No suitable driver constitute for jdbc: XXX error inward Java. The root crusade of this employment is wrong JDBC URL, to a greater extent than frequently than non the protocol usage is incorrect. This is non only a Microsoft SQL SERVER specific error but tin come upwards land connecting to whatever database e.g. MySQL using JDBC API. You must brand certain that JDBC URL is absolutely right every bit instructed past times driver manual.
Further Resources to Learn JDBC inward Java :
- Practical database programming alongside Java past times Ying Bai (book)
- JDBC Recipes: Influenza A virus subtype H5N1 Problem-Solution Approach past times Mahmoud Parsian (book)
- Step past times Step Guide to connect MySQL database using JDBC API (guide)
- Java guide to connect Oracle 10g database using JDBC sparse driver (guide)
- Solving java.lang.classnotfoundexception sun.jdbc.odbc.jdbcodbcdriver [solution]
- Fixing java.lang.ClassNotFoundException: org.postgresql.Driver [solution]
- Solving java.lang.classnotfoundexception oracle.jdbc.driver.oracledriver [solution]
- Dealing with java.lang.ClassNotFoundException: com.mysql.jdbc.Driver [fix]
Further Learning
JSP, Servlets together with JDBC for Beginners: Build a Database App
Complete JDBC Programming Part 1 together with 2
Java Platform: Working alongside Databases Using JDBC