I have problem with connecting my program to database, when I do everything in one file then it working, but when I want make it object oriented then it calls NullPinterException. There is code if you can help me:
Main.java:
public static void main(String[] args) {
try{
DbConnect.ConnectToDB();
}catch(Exception e){
System.out.println(e);
}
}
DatabaseConnect.java:
public class DatabaseConnect {
private static Connection connect;
public static String isClosed;
public void ConnectToDB(){
try{
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://127.0.0.1/warsztattest", "root", "");
}catch(Exception e){
System.out.println(e);
}
}
public String CheckConn() throws SQLException{
if (connect.isClosed()){
isClosed = "Disconnected";
}else{
isClosed = "Connected";
}
return isClosed;
}
}
DbConnect
declared? – Jimmy T. Jul 6 at 12:01