谁能告诉我自己做错了什么?我有一个数据库,其中包含一个名为henry_author
的表,如下所示:
Table Name: henry_author
| author_num | author |
-----------------------
| 0 | james |
| 1 | jack |
我试图从henry_author
表中获取这两个数字。
以下是我正在做的事情:
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();
}
}
我一直收到错误:java.lang.NullPointerException
。不知道代码有什么问题。