I used the following code segment for connecting my java application to mySQL DB, but its giving an error which I can't figure out why.
try {
con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "ass1";
String driver = "com.mysql.jdbc.Driver";
String user = "";
String pass = "";
System.out.println("OK 1"); //Checkpoint 1
Class.forName(driver).newInstance();
System.out.println("OK 2"); //Checkpoint 2
con = DriverManager.getConnection(url + db, user, pass);
System.out.println("OK 3"); //Checkpoint 3
}
catch (Exception e) {
System.out.println(e.getMessage());
}
Exception(Output):
run:
OK 1
com.mysql.jdbc.Driver
null
BUILD SUCCESSFUL(total time: 13 seconds)
So the exception is driver itself. It's the first time that I'm encountering this.
P.S.: Please ignore the checkpoints.