Can anyone tell me what I'm doing wrong? I have a database with a table called henry_author
that looks like this:
Table Name: henry_author
| author_num | author |
-----------------------
| 0 | james |
| 1 | jack |
I'm trying to get both the numbers from the henry_author
table.
Here is what I'm doing:
public static void main(String[] args) throws Exception {
Connection conn = null;
PreparedStatement pstmt = null;
Statement stmt = null;
try {
conn = getConnection(); // this is basically the DB_URL, USER, PASS and DriverManager.getConnection() method/function I made
String query = "SELECT author_num FROM henry_author";
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
int number = rs.getInt("author_num");
System.out.println("Author num: + number);
}
} catch (SQLException sqle) {
sqle.printStackTrace();
}
}
I keep getting the error: java.lang.NullPointerException
. No clue on what is wrong with the code.