hello
I am trying to connect to mysql database using connector/J jdbc driver
this is my code
import java.sql.Connec tion;
import java.sql.Driver Manager;
import java.sql.SQLExc eption;
import java.util.*;
class JdbcTest1 {
public static void main(String[] args) {
// Connection conn = null;
// Statement st = null;
//ResultSet rs = null;
//ResultSetMetaDa ta rmd = null;
String query = null;
try{
Class.forName(" com.mysql.jdbc. Driver").newIns tance();
System.out.prin tln("Driver Registration Successful.");
} catch (InstantiationE xception ie){
System.out.prin tln("Class Instantiation Exception: " + ie);
} catch (ClassNotFoundE xception cnf){
System.out.prin tln("Class Not Found Exception: " + cnf);
} catch (IllegalAccessE xception iae){
System.out.prin tln("Illegal Access Exception: " + iae);
}
try {
// conn =
DriverManager.g etConnection("j dbc:mysql://localhost:3306/mysql?user=root &pas
sword=root");
java.sql.Connec tion conn =
DriverManager.g etConnection("j dbc:mysql:///mysql","root", "root");
System.out.prin tln("Connection to MySQL Database Successful");
} catch (SQLException sqe1){
System.out.prin tln("Caught SQL Exception: " + sqe1);
}
}
}
The output is
Driver registeration successful
java.lang.NoCla ssDefFound error
com/mysql/jdbc/Connection
at com.mysql.jdbc. NonRegisteringD river.connect()
I am not able to figure out whether it is the URL problem to getConnection
or something else
please help
I am trying to connect to mysql database using connector/J jdbc driver
this is my code
import java.sql.Connec tion;
import java.sql.Driver Manager;
import java.sql.SQLExc eption;
import java.util.*;
class JdbcTest1 {
public static void main(String[] args) {
// Connection conn = null;
// Statement st = null;
//ResultSet rs = null;
//ResultSetMetaDa ta rmd = null;
String query = null;
try{
Class.forName(" com.mysql.jdbc. Driver").newIns tance();
System.out.prin tln("Driver Registration Successful.");
} catch (InstantiationE xception ie){
System.out.prin tln("Class Instantiation Exception: " + ie);
} catch (ClassNotFoundE xception cnf){
System.out.prin tln("Class Not Found Exception: " + cnf);
} catch (IllegalAccessE xception iae){
System.out.prin tln("Illegal Access Exception: " + iae);
}
try {
// conn =
DriverManager.g etConnection("j dbc:mysql://localhost:3306/mysql?user=root &pas
sword=root");
java.sql.Connec tion conn =
DriverManager.g etConnection("j dbc:mysql:///mysql","root", "root");
System.out.prin tln("Connection to MySQL Database Successful");
} catch (SQLException sqe1){
System.out.prin tln("Caught SQL Exception: " + sqe1);
}
}
}
The output is
Driver registeration successful
java.lang.NoCla ssDefFound error
com/mysql/jdbc/Connection
at com.mysql.jdbc. NonRegisteringD river.connect()
I am not able to figure out whether it is the URL problem to getConnection
or something else
please help