hello
I am trying to connect to mysql database using connector/J jdbc driver
this is my code
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.*;
class JdbcTest1 {
public static void main(String[] args) {
// Connection conn = null;
// Statement st = null;
//ResultSet rs = null;
//ResultSetMetaData rmd = null;
String query = null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance ();
System.out.println("Driver Registration Successful.");
} catch (InstantiationException ie){
System.out.println("Class Instantiation Exception: " + ie);
} catch (ClassNotFoundException cnf){
System.out.println("Class Not Found Exception: " + cnf);
} catch (IllegalAccessException iae){
System.out.println("Illegal Access Exception: " + iae);
}
try {
// conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql?user=root&pas
sword=root");
java.sql.Connection conn =
DriverManager.getConnection("jdbc:mysql:///mysql","root", "root");
System.out.println("Connection to MySQL Database Successful");
} catch (SQLException sqe1){
System.out.println("Caught SQL Exception: " + sqe1);
}
}
}
The output is
Driver registeration successful
java.lang.NoClassDefFound error
com/mysql/jdbc/Connection
at com.mysql.jdbc.NonRegisteringDriver.connect()
I am not able to figure out whether it is the URL problem to getConnection
or something else
please help