This mistake comes when you lot are trying to connect to MySQL database from Java computer program using JDBC but either the JDBC driver for MySQL is non available inward the classpath or it is non registered prior to calling the DriverManager.getConnection() method. In lodge to acquire the connectedness to the database, you lot must offset register the driver using Class.forName() method. You should telephone yell upward this method alongside the right the cite of the JDBC driver "com.mysql.jdbc.Driver" and this volition both charge together with register the driver alongside JDBC. The type iv JDBC driver for MySQL is bundled into MySQL connective JAR e.g. mysql-connector-java-5.1.18-bin.jar depending upon which version of MySQL database you lot are connecting. Make certain this JAR is available inward classpath before running your Java program, otherwise Class.forName() volition non last able to uncovering together with charge the shape together with throw java.lang.ClassNotFoundException: com.mysql.jdbc.Driver, about other dreaded JDBC error, which nosotros bring seen inward the before post.
Recently I bring seen a mutual designing of this mistake where a Java developer running his computer program Java SE half dozen expects that JDBC driver's JAR volition last automatically loaded yesteryear JVM because of autoloading of JDBC driver characteristic of JDBC 4.0 released inward JDK half dozen but misses the fox that the JDBC driver should besides last JDBC 4.0 compliant e.g. mysql-connector-java-5.1.18-bin.jar volition last automatically loaded but older version may not, fifty-fifty if you lot run on Java 6. See Core Java Volume ii - Advanced Features to larn to a greater extent than almost JDBC 4.0 features.
So, brand certain you lot bring both JDK half dozen together with a JDBC 4.0 compliant driver to leverage the auto-loading characteristic of JDBC 4.0 specification.
You tin ship away run across that nosotros got the "No suitable driver found" error inward JDBC. The argue was that JDBC API couldn't uncovering whatever Driver corresponding to "jdbc:mysql://" URL because nosotros bring non added the MySQL connective JAR which contains the JDBC driver required to connect to MySQL database.
I prefer -cp selection because it's unproblematic together with slow together with you lot tin ship away run across what is included inward classpath right inward the ascendence occupation itself, no take away to worry almost whether JAR is included inward CLASSPATH surroundings variable or not.
The mistake should become away only yesteryear adding JDBC driver inward the classpath if you lot are running on Java 6, which supports JDBC 4.0 together with the driver is besides JDBC 4.0 compliant e.g. mysql-connector-java-5.1.36-bin.jar. From JDBC 4.0, Java has introduced auto loading of JDBC driver, therefore you lot don't take away to charge or register it manually using Class.forName() method.
If you lot are non running on Java SE half dozen or your JDBC driver version doesn't back upward JDBC 4.0 together with so only add together the next occupation before calling DriverManager.getConnection() to charge together with register the MySQL JDBC driver. This volition solve the occupation (uncomment the occupation inward in a higher house program):
This throws checked java.lang.ClassNotFoundException so makes certain you lot grab it. I bring non caught it to proceed the code clutter gratuitous yesteryear introducing sweat together with grab statement.
So, inward short:
1) Just add together the MySQL JDBC JAR into classpath if you lot are running on Java SE half dozen together with driver is JDBC 4.0 compliant e.g. mysql-connector-java-5.1.36-bin.jar.
2) Alternatively, add together the MySQL JDBC driver to classpath e.g. mysql-connector-java-5.1.18-bin.jar together with telephone yell upward the Class.forName("com.mysql.jdbc.Driver"); to charge together with register the driver before calling DriverManager.getConnection() method.
You tin ship away besides banking concern check out JDBC API Tutorial together with Reference (3rd Edition) to larn to a greater extent than almost novel features introduced inward JDBC 3.0 together with JDBC 4.0 specification together with it is besides ane of the best books to larn JDBC API inward Java.
That's all almost how to gear upward "No suitable driver works life for jdbc:mysql://localhost:3306/mysql" mistake inward Java. You tin ship away acquire this mistake from Eclipse or NetBeans IDE spell connecting to local MySQL event listening on default port 3306, don't afraid, only follow the same approach. Drop the MySQL JDBC driver together with telephone yell upward the Class.forName() method alongside the cite of the shape alongside implements Driver interface from JDBC API.
Related JDBC Tutorials for Java Programmers
Recently I bring seen a mutual designing of this mistake where a Java developer running his computer program Java SE half dozen expects that JDBC driver's JAR volition last automatically loaded yesteryear JVM because of autoloading of JDBC driver characteristic of JDBC 4.0 released inward JDK half dozen but misses the fox that the JDBC driver should besides last JDBC 4.0 compliant e.g. mysql-connector-java-5.1.18-bin.jar volition last automatically loaded but older version may not, fifty-fifty if you lot run on Java 6. See Core Java Volume ii - Advanced Features to larn to a greater extent than almost JDBC 4.0 features.
So, brand certain you lot bring both JDK half dozen together with a JDBC 4.0 compliant driver to leverage the auto-loading characteristic of JDBC 4.0 specification.
How to reproduce "No suitable driver works life for 'jdbc:mysql://localhost:3306/"
In lodge to amend sympathize this error, let's offset reproduce this mistake yesteryear executing next Java program. I aspect this computer program to throw the "No suitable driver works life for 'jdbc:mysql://localhost:3306/" mistake because I don't bring JDBC driver inward the classpath.import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; /* * Java Program to to reproduce * java.sql.SQLException: No suitable driver works life for jdbc:mysql://localhost:3306 * mistake which occurs if MySQL JDBC Driver JAR is missing * or you lot non registering the JDBC driver before calling * DriverManager.getConnection() method inward JDBC. */ public class MySQLTest { public static void main(String[] args) throws ClassNotFoundException { Connection con = null; try { String url = "jdbc:mysql://localhost:3306/mysql"; String username = "root"; String password = "root"; // Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection(url, username, password); if (con != null) { System.out .println("Successfully connected to MySQL database test"); } } catch (SQLException ex) { System.out .println("An mistake occurred spell connecting MySQL databse"); ex.printStackTrace(); } } } Output An mistake occurred while connecting MySQL databse java.sql.SQLException: No suitable driver works life for jdbc:mysql://localhost:3306/mysql at java.sql.DriverManager.getConnection(DriverManager.java:596) at java.sql.DriverManager.getConnection(DriverManager.java:215)
You tin ship away run across that nosotros got the "No suitable driver found" error inward JDBC. The argue was that JDBC API couldn't uncovering whatever Driver corresponding to "jdbc:mysql://" URL because nosotros bring non added the MySQL connective JAR which contains the JDBC driver required to connect to MySQL database.
How to solve "No suitable driver works life for jdbc:mysql://localhost:3306/mysql"
You tin ship away solve this occupation offset yesteryear adding MySQL connective JAR, which includes JDBC driver for MySQL into classpath e.g. mysql-connector-java-5.1.18-bin.jar. It's really easy, only download the JAR from MySQL website together with driblet it into your classpath. For Example, if you lot are running inward Eclipse together with so you lot tin ship away driblet it on the origin of your projection folder. Same is truthful for Netbeans, but if you lot are running your Java computer program from the ascendence prompt together with so either purpose -cp selection or laid the CLASSPATH every bit described here.I prefer -cp selection because it's unproblematic together with slow together with you lot tin ship away run across what is included inward classpath right inward the ascendence occupation itself, no take away to worry almost whether JAR is included inward CLASSPATH surroundings variable or not.
java -cp mysql-connector-java-5.1.18-bin.jar:. MySQLTest
The mistake should become away only yesteryear adding JDBC driver inward the classpath if you lot are running on Java 6, which supports JDBC 4.0 together with the driver is besides JDBC 4.0 compliant e.g. mysql-connector-java-5.1.36-bin.jar. From JDBC 4.0, Java has introduced auto loading of JDBC driver, therefore you lot don't take away to charge or register it manually using Class.forName() method.
If you lot are non running on Java SE half dozen or your JDBC driver version doesn't back upward JDBC 4.0 together with so only add together the next occupation before calling DriverManager.getConnection() to charge together with register the MySQL JDBC driver. This volition solve the occupation (uncomment the occupation inward in a higher house program):
Class.forName("com.mysql.jdbc.Driver");
This throws checked java.lang.ClassNotFoundException so makes certain you lot grab it. I bring non caught it to proceed the code clutter gratuitous yesteryear introducing sweat together with grab statement.
So, inward short:
1) Just add together the MySQL JDBC JAR into classpath if you lot are running on Java SE half dozen together with driver is JDBC 4.0 compliant e.g. mysql-connector-java-5.1.36-bin.jar.
2) Alternatively, add together the MySQL JDBC driver to classpath e.g. mysql-connector-java-5.1.18-bin.jar together with telephone yell upward the Class.forName("com.mysql.jdbc.Driver"); to charge together with register the driver before calling DriverManager.getConnection() method.
You tin ship away besides banking concern check out JDBC API Tutorial together with Reference (3rd Edition) to larn to a greater extent than almost novel features introduced inward JDBC 3.0 together with JDBC 4.0 specification together with it is besides ane of the best books to larn JDBC API inward Java.
That's all almost how to gear upward "No suitable driver works life for jdbc:mysql://localhost:3306/mysql" mistake inward Java. You tin ship away acquire this mistake from Eclipse or NetBeans IDE spell connecting to local MySQL event listening on default port 3306, don't afraid, only follow the same approach. Drop the MySQL JDBC driver together with telephone yell upward the Class.forName() method alongside the cite of the shape alongside implements Driver interface from JDBC API.
Related JDBC Tutorials for Java Programmers
- How to connect to MySQL database from Java Program (Guide)
- How to connect to Oracle database from Java (Guide)
- How to connect to Microsoft SQL Server from Java (Guide)
- How to setup JDBC connectedness Pool inward Spring + Tomcat (Guide)
- 10 JDBC Best Practices Java Programmer Should Follow (see here)
- 6 JDBC Performance Tips for Java Applications (see here)
![java.sql.SQLException: No suitable driver works life for 'jdbc:mysql://localhost:3306/mysql [Solution] This mistake comes when you lot are trying to connect to MySQL database from Java computer program using java.sql.SQLException: No suitable driver works life for 'jdbc:mysql://localhost:3306/mysql [Solution]](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNZ75us9PjSMrAZnKx_NAqO9qLAI8veVTvHvxDOjsBupGCghlIToN8QMQ7QWi0kBUIFfdo3vGbshMUEetoxRIqvDsNc47HqQAEquJ3qtrQPjq1wZ1Eu4Y1hoXVGxyWLNaGPlq_DqGFiwE/s320/Core+Java+Volume+2+10th+Edition.jpg)
![java.sql.SQLException: No suitable driver works life for 'jdbc:mysql://localhost:3306/mysql [Solution] This mistake comes when you lot are trying to connect to MySQL database from Java computer program using java.sql.SQLException: No suitable driver works life for 'jdbc:mysql://localhost:3306/mysql [Solution]](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLQDIBiJBWCEx2GtGPAYyjAYuaE9tIFPZGZAxY8H7Ls387YCElvp4Ao49W9bwSL4DtDS0jh4Ik9wECq20RmcL-w1AdHLdQZTRzS5jTKd8bFW-z6E_ruFt_MSYvklfuFRlMm6QR-G9JawA/s400/How+to+solve+No+Suitable+driver+found+erorr+in+MySQL.jpg)
![java.sql.SQLException: No suitable driver works life for 'jdbc:mysql://localhost:3306/mysql [Solution] This mistake comes when you lot are trying to connect to MySQL database from Java computer program using java.sql.SQLException: No suitable driver works life for 'jdbc:mysql://localhost:3306/mysql [Solution]](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjl-Q2Qukd8hZjeuuPNSghEVEPF_w6xpXMUN69WAzzBdrpF4Ohj6Eoqied8gAclPo7ahAUhq9mO4Li64NXCzahVu02WbHywzgYINRCYvYnU-wuXdKhD5mFdgtx09zbEy3dCzfitAcWonhc/s320/JDBC+API+and+Tutorial+book.jpg)
0 Response to "java.sql.SQLException: No suitable driver institute for 'jdbc:mysql://localhost:3306/mysql [Solution]"
Posting Komentar