Java.Sql.Sqlexception: No Suitable Driver Establish For Jdbc:Jtds:Sqlserver - Elbow Grease As Well As Solution
java.sql.SQLException: No suitable driver works life for
There are 2 ways to connect Microsoft SQL Server from Java program, either yesteryear using Microsoft's official JDBC driver (sqljdbc4.jar), or yesteryear using jTDS driver (jtds.jar). This error comes when your supplied database URL didn't stand upward for alongside the JDBC driver introduce inward the CLASSPATH. Many programmers who commonly job jtds.jar, makes a error spell using sqljdbc4.jar yesteryear adding "microsoft" inward JDBC URL. That makes URL invalid too JDBC API throws "java.sql.SQLException: No suitable driver : sqljdbc4.jar" error.
For Example inward JTDS, the JDBC URL format is
jdbc:jtds:://[:][/][;=[;...]]
too spell 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, too portNumber is optional. If y'all don't render serverName too then SQL server volition expect into properties collection, if an instance is non specified too then JDBC volition connect to default instance too if the port position out is non specified too then it volition connect to default SQL Server port position out 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 guild to solve this error, simply add together jtds.jar inward CLASSPATH of your Java application. If y'all don't conduct maintain jtds.jar, y'all tin displace download it from here. Alternatively, y'all tin displace too add together next Maven dependency, if y'all are using Maven to construct your projection :
If y'all already conduct maintain this JAR file inward your CLASSPATH but even thus getting inward a higher house error, mayhap it's fourth dimension to revisit your CLASSPATH settings. See Core Java, Volume II--Advanced Features yesteryear Cay S. Horstmann to larn to a greater extent than almost JDBC drivers too URL.
2) Many junior programmer's brand error of including "microsoft" in JDBC URL for SQL SERVER similar "jdbc:microsoft:sqlserver://localhost:1433", spell using sqljdbc4.jar file to connect MSSQL database. This volition result inward the next exception :
In guild to create this error simply take microsoft from URL. Correct JDBC URL format to connect SQL SERVER is "jdbc:sqlserver://localhost:1433";. No ask to worry almost CLASSPATH, because if the SQLJDBC4.jar is non introduce too then it volition laissez passer y'all a dissimilar error, something similar java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver.
3) The tertiary mutual argue of No suitable driver works life 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 rattling hard to spot that instead of writing "jtds", y'all conduct maintain written "jdts". I conduct maintain seen this error many times, exclusively to realize afterwards spending hours checking CLASSPATH settings. You volition locomote greeted alongside next error :
Solving this error is easy, simply right the spelling inward JDBC URL too y'all are done.
4) The quaternary argue for getting No suitable driver works life an error spell 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 job jTDS driver inward the evolution environs too Microsoft JDBC driver (sqljdbc4.jar) inward the production environment.
In guild to solve that error, simply take jTDS driver too add together Microsoft JDBC driver i.e. sqljdbc4.jar inward your project's construct path.
That's all almost how to solve java.sql.SQLException: No suitable driver works life for jdbc: XXX error inward Java. The root motility of this job is wrong JDBC URL, to a greater extent than oft than non the protocol role is incorrect. This is non simply a Microsoft SQL SERVER specific error but tin displace come upward spell connecting to whatsoever database e.g. MySQL using JDBC API. You must brand certain that JDBC URL is absolutely right every bit instructed yesteryear driver manual.
Further Resources to Learn JDBC inward Java :
Further Learning
JSP, Servlets too JDBC for Beginners: Build a Database App
Complete JDBC Programming Part 1 too 2
Java Platform: Working alongside Databases Using JDBC
There are 2 ways to connect Microsoft SQL Server from Java program, either yesteryear using Microsoft's official JDBC driver (sqljdbc4.jar), or yesteryear using jTDS driver (jtds.jar). This error comes when your supplied database URL didn't stand upward for alongside the JDBC driver introduce inward the CLASSPATH. Many programmers who commonly job jtds.jar, makes a error spell using sqljdbc4.jar yesteryear adding "microsoft" inward JDBC URL. That makes URL invalid too JDBC API throws "java.sql.SQLException: No suitable driver : sqljdbc4.jar" error.
For Example inward JTDS, the JDBC URL format is
jdbc:jtds:://[:][/][;=[;...]]
too spell 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, too portNumber is optional. If y'all don't render serverName too then SQL server volition expect into properties collection, if an instance is non specified too then JDBC volition connect to default instance too if the port position out is non specified too then it volition connect to default SQL Server port position out 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 works life for jdbc: error spell connecting to SQL SERVER 2008, 2012 too 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 works life for jdbc:jtds://localhost:1434 at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source)
In guild to solve this error, simply add together jtds.jar inward CLASSPATH of your Java application. If y'all don't conduct maintain jtds.jar, y'all tin displace download it from here. Alternatively, y'all tin displace too add together next Maven dependency, if y'all are using Maven to construct your projection :
<dependency> <groupId>net.sourceforge.jtds</groupId> <artifactId>jtds</artifactId> <version>1.3.1</version> </dependency>
If y'all already conduct maintain this JAR file inward your CLASSPATH but even thus getting inward a higher house error, mayhap it's fourth dimension to revisit your CLASSPATH settings. See Core Java, Volume II--Advanced Features yesteryear Cay S. Horstmann to larn to a greater extent than almost JDBC drivers too URL.
2) Many junior programmer's brand error of including "microsoft" in JDBC URL for SQL SERVER similar "jdbc:microsoft:sqlserver://localhost:1433", spell using sqljdbc4.jar file to connect MSSQL database. This volition result inward the next exception :
java.sql.SQLException: No suitable driver works life for jdbc:microsoft:sqlserver://localhost:1433 at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source)
In guild to create this error simply take microsoft from URL. Correct JDBC URL format to connect SQL SERVER is "jdbc:sqlserver://localhost:1433";. No ask to worry almost CLASSPATH, because if the SQLJDBC4.jar is non introduce too then it volition laissez passer y'all a dissimilar error, something similar java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver.
3) The tertiary mutual argue of No suitable driver works life 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 rattling hard to spot that instead of writing "jtds", y'all conduct maintain written "jdts". I conduct maintain seen this error many times, exclusively to realize afterwards spending hours checking CLASSPATH settings. You volition locomote greeted alongside next error :
java.sql.SQLException: No suitable driver works life for jdbc:jdts://localhost:1434 at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source)
Solving this error is easy, simply right the spelling inward JDBC URL too y'all are done.
4) The quaternary argue for getting No suitable driver works life an error spell 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 job jTDS driver inward the evolution environs too Microsoft JDBC driver (sqljdbc4.jar) inward the production environment.
java.sql.SQLException: No suitable driver works life for jdbc:sqlserver://localhost:1433 at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source)
In guild to solve that error, simply take jTDS driver too add together Microsoft JDBC driver i.e. sqljdbc4.jar inward your project's construct path.
That's all almost how to solve java.sql.SQLException: No suitable driver works life for jdbc: XXX error inward Java. The root motility of this job is wrong JDBC URL, to a greater extent than oft than non the protocol role is incorrect. This is non simply a Microsoft SQL SERVER specific error but tin displace come upward spell connecting to whatsoever database e.g. MySQL using JDBC API. You must brand certain that JDBC URL is absolutely right every bit instructed yesteryear driver manual.
Further Resources to Learn JDBC inward Java :
- Practical database programming alongside Java yesteryear Ying Bai (book)
- JDBC Recipes: Influenza A virus subtype H5N1 Problem-Solution Approach yesteryear Mahmoud Parsian (book)
- Step yesteryear 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 too JDBC for Beginners: Build a Database App
Complete JDBC Programming Part 1 too 2
Java Platform: Working alongside Databases Using JDBC


Komentar
Posting Komentar