Hey guys,
i found this tutorial online that involved searching your database for an existing value. I have changed the code around so it fits with my system but when i run it the input displays but once i press ok the input box closes and nothin else happens.
Heres the Code :
private void checkButtonActionPerformed(java.awt.event.ActionEvent evt) {
Scanner sc = new Scanner(System.in);
try{
java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/ireland","root" ,"password");
Statement stmt = con.createStatement();
JOptionPane.showInputDialog("Please Enter the pubs name you wish to search.");
String pubName = sc.next();
String SQL = "SELECT * FROM pubs WHERE Pub_Name = '" + pubName +"'";
ResultSet rs = stmt.executeQuery(SQL);
if (rs.next()) {
JOptionPane.showMessageDialog(null, "Pub already exists!!");
}
else {
JOptionPane.showMessageDialog(null, "Pub doesn't exists!!");
}
}
catch (Exception e){
JOptionPane.showMessageDialog( null, "There was a problem inserting into the database please try again ", "ERROR", JOptionPane.ERROR_MESSAGE);
}
}
Can anyone tell me whats goin on ??
Thanks :)