'non-static method openConnection() cannot be referenced from a static context [duplicate]

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;
}
}


Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 abdurrhman el shimy