JDBC stands for Java DataBase Connectivity. JDBC is a standard Java API for database-independent connectivity between the Java programming language and a wide range of databases. By using JDBC, a Java application can access any kind of tabular data, especially data stored in a Relational Database. JDBC works with Java on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX.
By following the steps users can run SQL commands with java. The most common error that arises when using JDBC in cmd is Java.lang.ClassNotFoundException: com.mysql.jdbc.driver or no suitable driver found for jdbc:mysql://localhost/. By following the below steps you can tackle these errors.
Follow the steps below to set up JDBC in the latest JDK.
- Download the JDBC connector by going here.
- Select Operating System as Platform Independent.
- Download the zip file.
- Extract the zip file and copy the mysql-connector-java.jar
- Go to the installation directory of Java.
Create a folder named ext and paste mysql-connector-java.jar in that folder.
- Open Advanced System Settings. If you don’t know how to open the Advanced System Settings follow this guide. Open Advanced System Setting in Windows 10 (three solutions)!
- Click Environment Variables.
- In System Variable click New Button.
Variable Name: classpath
Variable Value: C:\Program Files\Java\jdk-14.0.2\ext\mysql-connector-java-8.0.21.jar;.
Make sure to include semicolon and a dot at last ;.
- Done, now you can compile the JDBC program and run.