i trying my hand at this program called Crime Scene Investigation: I have just did the login screen. I want to use a database to login to validate the users but i am getting this errors with the codes that I used.
and this is error am receiving when I tried to login
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
public class CrimeSceneInvestigation extends javax.swing.JFrame {
public CrimeSceneInvestigation() {
initComponents();
}
private void jButton_CancelActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
}
private void jButton_submitActionPerformed(java.awt.event.ActionEvent evt) {
if(jTextField_username.getText().length() == 0){
JOptionPane.showMessageDialog(null, "empty credentials detected, fill it up ");
}
else if(jPasswordField_passwrd.getPassword().length == 0){
JOptionPane.showMessageDialog(null, "empty credential detected, please fill it up");
}
else{
String user = jTextField_username.getText();// getting the input
char[] pass = jPasswordField_passwrd.getPassword();//getting the input
String pwd = String.copyValueOf(pass);
if(validate_login(user, pwd)){
JOptionPane.showMessageDialog(null, "Valid login credentials");
}
else{
JOptionPane.showMessageDialog(null, "Invlaid long credentials");
}
}
}
private boolean validate_login(String user, String pwd) {
try{
Class.forName("com.mysql.jdbc.Driver");// db connection
Connection conn =DriverManager.getConnection("jdbc.mysql://localhost:3306/crime_Scene_investigation" , "dbuser","dbpass");
PreparedStatement stmt = conn.prepareStatement("Select * from login where username AND password");
stmt.setString(1, user);
stmt.setString(2, pwd);
ResultSet rs = stmt.executeQuery();
if(rs.next()){
return true;
}
else{
return false;
}
}
catch(Exception e){
e.printStackTrace();
}
return false;
}
Runnable() {
@Override
public void run() {
new CrimeSceneInvestigation().setVisible(true);
}
});
}at CrimeSceneInvestigation.validate_login(CrimeSceneInvestigation.java:131) at CrimeSceneInvestigation.jButton_submitActionPerformed(CrimeSceneInvestigation.java:115) at CrimeSceneInvestigation.access$100(CrimeSceneInvestigation.java:8) at CrimeSceneInvestigation$2.actionPerformed(CrimeSceneInvestigation.java:80)

