public class Actor {
String URL = "jdbc:mysql://localhost:3306/test/phone";
String USERNAME = "root";
String PASSWORD = "";
Connection connection = null;
PreparedStatement selectActors = null;
ResultSet resultSet = null;
public Actor(){
try {
connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
selectActors = connection.prepareStatement( "SELECT * FROM phone");
} catch (SQLException e) {
e.printStackTrace();
}
}
public ResultSet getActors() {
try {
resultSet = selectActors.executeQuery();
return resultSet;
} catch (SQLException e) {
e.printStackTrace();
}
return resultSet;
}
}
I'm trying to write Java code to connect to a database and display all the records in a table, but it won't work. The error I'm getting is a null pointer exception on getActors(). I've tried checking why the null pointer exception occurs but I just cannot get it. Everything else works just fine