Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connecting to MySQL database using JDBC

Status
Not open for further replies.

JTan

Technical User
Oct 9, 2001
73
SG
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
}

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top