I have two classes, in the first one I declare my connection to the derby database
static final String DATABASE_URL = "jdbc:derby://localhost:1527/A3";
Connection conn = null;
public ConnectionToSql() throws ClassNotFoundException {
try {
conn = DriverManager.getConnection(
DATABASE_URL, "root", "1234" );
} catch (SQLException e) {
}
and in my second class I use a preparedStatement
public String validateUser(String username, String password) {
try {
PreparedStatement ps = (PreparedStatement) conn.prepareStatement("SELECT * FROM users where username = ? and password = ?");
ps.setObject(1, username);
ps.setObject(2, password);
ResultSet rs = ps.executeQuery();
and I get: Exception in thread "Thread-0" java.lang.NullPointerException at Server.SqlRepository.validateUser(SqlRepository.java:28)
Line 28 is the line with the prepared statement. Sorry about formatting.