Create a new Connection object from the DriverManager class. * DriverManager.getConnection() method in JDBC. To connect to MySQL database from a Java program, you need to do the following steps: Load the MySQL Connector/J into your program. * or you not registering the JDBC driver before calling * error which occurs if MySQL JDBC Driver JAR is missing
\javatest\mysqltest>java -classpath mysql-connector. I expect this program to throw the "No suitable driver found for 'jdbc:mysql://localhost:3306/" error because I don't have JDBC driver in the classpath. I tried to run the following piece of code but it failed to load the JDBC driver and generated an exception. In order to better understand this error, let's first reproduce this error by executing following Java program.
java -jar Fill in the connection properties and copy the connection string to the clipboard. Either double-click the JAR file or execute the jar file from the command-line.
LOAD THE MYSQL JDBC DRIVER JAVA HOW TO
How to reproduce the "No suitable driver found for 'jdbc:mysql://localhost:3306/" Error in Java? For assistance in constructing the JDBC URL, use the connection string designer built into the MySQL JDBC Driver. You can further see these free JDBC courses to learn more about JDBC 4.0 features. So, make sure you have both JDK 6 and a JDBC 4.0 compliant driver to leverage the auto-loading feature of JDBC 4.0 specification. Recently I have seen a common pattern of this error where a Java developer running his program on a version higher than Java SE 6 expects that JDBC driver's JAR will be automatically loaded by JVM because of autoloading of JDBC driver feature of JDBC 4.0 released in JDK 6 but misses the trick that the JDBC driver should also be JDBC 4.0 compliant like mysql-connector-java-5.1.18-bin.jar will be automatically loaded but older version may not, even if you run on Java 6. Make sure this JAR is available in classpath before running your Java program, otherwise Class.forName() will not be able to find and load the class and throw :, another dreaded JDBC error, which we have seen in the earlier post.