Hi all,
I had followed the steps in MySQL webpage to install the driver and do the coding accordingly. However, I still get the SQL exception error: com.mysql.jdbc.Driver when I tried to execute the program. May I know what is wrong?
============================================================
Codes
============================================================
private void confirm(java.awt.event.ActionEvent evt) {
Connection conn = null;
if (!(jPasswordField.getPassword().toString().equals(null)) && !(txtid.getText().length() == 0)) {
try {
Class.forName ("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost/VPG", "root", "root");
// Do something with the Connection
//conn.setAutoCommit (false);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT password from member where member_id = '" + txtid.getText() + "';");
rs.first();
String results = (String)rs.getObject(1);
if (new String(jPasswordField.getPassword()).compareTo(results) == 0 )
{
hide();
Main main = new Main();
main.show();
}else {
// txtresults.setText(jPasswordField.getPassword().toString());
txtresults.setText("Incorrect User ID/password! Please try again.");
}
} catch (Exception e) {
// handle any errors
txtresults.setText("Cannot connect to the server.");
}
finally {
// it is a good idea to release
// resources in a finally{} block
// in reverse-order of their creation
// if they are no-longer needed
if (conn != null) {
try {
conn.close();
} catch (Exception e) { txtresults.setText(e.getMessage());
}//if
}//finally
}
}
I had followed the steps in MySQL webpage to install the driver and do the coding accordingly. However, I still get the SQL exception error: com.mysql.jdbc.Driver when I tried to execute the program. May I know what is wrong?
============================================================
Codes
============================================================
private void confirm(java.awt.event.ActionEvent evt) {
Connection conn = null;
if (!(jPasswordField.getPassword().toString().equals(null)) && !(txtid.getText().length() == 0)) {
try {
Class.forName ("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost/VPG", "root", "root");
// Do something with the Connection
//conn.setAutoCommit (false);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT password from member where member_id = '" + txtid.getText() + "';");
rs.first();
String results = (String)rs.getObject(1);
if (new String(jPasswordField.getPassword()).compareTo(results) == 0 )
{
hide();
Main main = new Main();
main.show();
}else {
// txtresults.setText(jPasswordField.getPassword().toString());
txtresults.setText("Incorrect User ID/password! Please try again.");
}
} catch (Exception e) {
// handle any errors
txtresults.setText("Cannot connect to the server.");
}
finally {
// it is a good idea to release
// resources in a finally{} block
// in reverse-order of their creation
// if they are no-longer needed
if (conn != null) {
try {
conn.close();
} catch (Exception e) { txtresults.setText(e.getMessage());
}//if
}//finally
}
}