0

I am getting some error stating executing query is passing null value. can any body help me. I am trying to connect to my local database, extract value and if the input value and value in database matches,it eventually will log in. but there is something error that I couldn't figure what is wrong. I checked the drivers and modules but they are doing fine.

    @Override
    public void actionPerformed(ActionEvent ae) {
        if(ae.getSource()==b1){
        String user=t1.getText();
        String password =t2.getText();
        MySQLConnection conn = new MySQLConnection();
        String st = "select * from hotel where username='"+user+"' and password='"+password+"'";
        try {

           ResultSet se= conn.s.executeQuery(st);
           if(se.next()){
               new HotelManagementSystem().setVisible(true);
           }
           else{
               JOptionPane.showMessageDialog(null,"Invalid username or password");
           }
            this.setVisible(false);
        }
        catch (Exception e){
            e.printStackTrace();
        }
        }
        else if(ae.getSource()==b2){
            System.exit(0);
        }
    }
public class MySQLConnection {
    Connection c;
    Statement s;

    public MySQLConnection() {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/hotel", "root", "");
            Statement s = c.createStatement();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Mark Rotteveel
  • 90,369
  • 161
  • 124
  • 175
  • Something is null, probably `s`. You shouldn't catch exceptions and continue on as if nothing happened. Likely the `MySQLConnection` constructor had an exception, which you caught and ignored. Check what exception it produced. – Mark Rotteveel Jan 09 '22 at 09:39

0 Answers0