JDBC Problem - com.mysql.jdbc.Driver
I am trying to connect to my MySQL DB with JDBC but I am having a problem with my servlet. I have my Data Access Object class which is able to establish a connection with the db. In my servlet init() function, I try to establish a connection using my DAO class but I keep getting the error message "com.mysql.jdbc.Driver". I do not understand what is happening as this worked fine in the DAO class.
Servlet.java
Code :
private Dao dao = new Dao();
public void init() {
dao.connectToDB();
}
Dao.java
Code :
public void connectToDB() {
try {
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (databaseURL, userName, password);
System.out.println ("Database connection established");
} catch (Exception e) {
System.err.println ("Cannot connect to database server");
System.err.println ("Error message: " + e.getMessage());
} finally {
if (conn != null) {
try {
conn.close ();
System.out.println ("Database connection terminated");
} catch (Exception e) { }
}
}
}
Re: JDBC Problem - com.mysql.jdbc.Driver
What is the exception message?
Paste here so that we could look over it. Also give the details about your variables, i mean where are they declared and what are there datatypes and scope too.
Re: JDBC Problem - com.mysql.jdbc.Driver