I've tried executing the code below but the error that I get is "Error: com.mysql.jdbc.Driver" I downloaded the connection driver and configured the class path but the error persists. Please please help here coz I have tried to locate the problem but I can't find it. In addition to that, I have switched off the firewall just in case it is blocking the connection but there is no change. import java.sql.*; public class jdbctestcon { public static void main(String args[]) { System.out.println("MySQL Connect Example."); Connection conn = null; String url = "jdbc:mysql://localhost/"; String dbName = "textbook"; String driver = "com.mysql.jdbc.Driver"; String userName = "root"; String password = ""; try { Class.forName(driver).newInstance(); conn = DriverManager.getConnection(url+dbName,userName,password); System.out.println("Connected to the database"); conn.close(); System.out.println("Disconnected from database"); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } } }
Do you have mysql-connector-java-5.0.8-bin.jar file in jdk lib? If not then put it.
For more information, visit the following link:
I have mysql-connector-java-5.1.17-bin.jar. Does the version really matter? I copied the connector to jdk lib and also configured the CLASSPATH to match the the location of the driver in the jdk lib, but still the error that I still get is "com.mysql.jdbc.Driver". What could be missing here?