Answer the question
In order to leave comments, you need to log in
Why can't I call a static method from another class?
There are 2 classes. They are in the same package.
DBHandler class:
package utils;
import java.sql.*;
public class DBHandler {
static Connection connection;
public static boolean openConnection() {
try {
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/demotest", "root", "");
return true;
} catch (SQLException throwables) {
throwables.printStackTrace();
return false;
}
}
public static boolean closeConnection() {
try {
connection.close();
return true;
} catch (SQLException throwables) {
throwables.printStackTrace();
return false;
}
}
public static ResultSet executeQuery (String sql) {
ResultSet resultSet = null;
try {
PreparedStatement preparedStatement = connection.prepareStatement(sql);
if (sql.contains("SELECT")) {
resultSet = preparedStatement.executeQuery();
} else {
preparedStatement.executeUpdate();
}
} catch (SQLException throwables) {
throwables.printStackTrace();
}
return resultSet;
}
}
package utils;
public class ClientTable {
DBHandler.openConnection();
}
C:\Users\mk_11\IdeaProjects\AutoService002\src\utils\ClientTable.java:4:29
java: <identifier> expected
Answer the question
In order to leave comments, you need to log in
package utils;
public class ClientTable {
DBHandler.openConnection();
}
package utils;
public class ClientTable {
private void call() {
DBHandler.openConnection();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question