Java.Sql.Sqlexception: No Suitable Driver Industrial Plant Life For Jdbc:Jtds:Sqlserver - Travail Together With Solution

java.sql.SQLException: No suitable driver works life for 
There are ii 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 tally alongside the JDBC driver introduce inwards the CLASSPATH. Many programmers who commonly utilization jtds.jar, makes a error piece using sqljdbc4.jar yesteryear adding "microsoft" inwards JDBC URL. That makes URL invalid in addition to JDBC API throws "java.sql.SQLException: No suitable driver : sqljdbc4.jar" error.


For Example inwards JTDS, the JDBC URL format is

jdbc:jtds:://[:][/][;=[;...]]

in addition to piece 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 besides known equally sub-protocol. All other parameters e.g. serverName, instanceName, in addition to portNumber is optional. If y'all don't supply serverName in addition to then SQL server volition await into properties collection, if an instance is non specified in addition to then JDBC volition connect to default instance in addition to if the port expose is non specified in addition to then it volition connect to default SQL Server port expose 1433.

 There are ii ways to connect Microsoft SQL Server from Java computer program java.sql.SQLException: No suitable driver works life for jdbc:jtds:sqlserver - Cause in addition to Solution




Common reasons of "No suitable driver found" Error

Let's come across to a greater extent than or less of the most mutual reasons for getting java.sql.SQLException: No suitable driver works life for jdbc: error piece connecting to SQL SERVER 2008, 2012 in addition to 2019.

1) You are using JDBC URL format for jTDS driver (jdbc:jtds://localhost:1434";)  but deployed sqljdbc4.jar inwards 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 gild to solve this error, only add together jtds.jar inwards 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 besides 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 inwards your CLASSPATH but even hence getting higher upwardly error, peradventure 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 nigh JDBC drivers in addition to URL.




2) Many junior programmer's brand error of including "microsoft" in JDBC URL for SQL SERVER similar  "jdbc:microsoft:sqlserver://localhost:1433", piece using sqljdbc4.jar file to connect MSSQL database. This volition effect inwards 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 gild to create this error only take away microsoft from URL. Correct JDBC URL format to connect SQL SERVER is "jdbc:sqlserver://localhost:1433";.  No ask to worry nigh CLASSPATH, because if the SQLJDBC4.jar is non introduce in addition to then it volition plough over y'all a dissimilar error, something similar java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver.


3)  The 3rd 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 real hard to location that instead of writing "jtds", y'all receive got written "jdts". I receive got seen this error many times, alone to realize afterward spending hours checking CLASSPATH settings.  You volition live on 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, only right the spelling inwards JDBC URL in addition to y'all are done.



4) The 4th argue for getting No suitable driver works life an error piece connecting to MSSQL is specifying JDBC URL equally "jdbc:sqlserver://localhost:1433" but deployed jTDS driver inwards application's CLASSPATH. This happens because many developers utilization jTDS driver inwards the evolution surroundings in addition to Microsoft JDBC driver (sqljdbc4.jar) inwards 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 gild to solve that error, only take away jTDS driver in addition to add together Microsoft JDBC driver i.e. sqljdbc4.jar inwards your project's create path.


That's all nigh how to solve java.sql.SQLException: No suitable driver works life for jdbc: XXX error inwards Java. The root drive of this work is wrong JDBC URL, by in addition to large the protocol utilization is incorrect. This is non only a Microsoft SQL SERVER specific error but tin come upwardly piece connecting to whatever database e.g. MySQL using JDBC API. You must brand certain that JDBC URL is absolutely right equally instructed yesteryear driver manual.

Further Resources to Learn JDBC inwards 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 in addition to JDBC for Beginners: Build a Database App
Complete JDBC Programming Part 1 in addition to 2
Java Platform: Working alongside Databases Using JDBC

Belum ada Komentar untuk "Java.Sql.Sqlexception: No Suitable Driver Industrial Plant Life For Jdbc:Jtds:Sqlserver - Travail Together With Solution"

Posting Komentar

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel