-4

The problem appears in openConnection(). I've tried all solutions and they didn't work. Can someone save me and write the solution in details that I can understand it?

package cabinet.database;

import cabinet.Admin;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class logincc {
        Statement st;

  public boolean islogin(Admin ad)throws SQLException{
         st= Connection.openConnection().createStatement();
    ResultSet res=  st.executeQuery("select*from mote de passe where username ='"+ad.getUsername()+"'and password='"+ ad.getPassword()+"'" );
    if (res.next())
  return true;
  return false;
}
}
khelwood
  • 55,782
  • 14
  • 81
  • 108
  • 3
    What do you need to know that isn’t explained by the error message? `openConnection()` is an instance method, you can’t call it with a class name (the “static context”) – James_D May 06 '22 at 18:56

1 Answers1

2

Based on the error in the title, this question might be helpful. Non-static methods need an instance, such as new Connection() and can't be called without creating an instance.

I'm not sure what library you're using to create the connection but this shows an example of how you would do this in Java.