我很擅长使用Java中的SQL东西,我正在尝试选择我在Oracle中创建的视图并打印出它的内容,但是我得到了一个nullpointerexception
try {
conn = DriverManager.getConnection(dbURL, user, password);
conn.clearWarnings();
System.out.println("Connection opened! for driver ==>Oracle 11XE");
while (!option.equalsIgnoreCase("X"))
{
System.out.print("What to do Q1 (1) Q2 (2) or (X) exit: ");
option = s.nextLine();
System.out.println("");
if (option.equalsIgnoreCase("1"))
{
System.out.println("ID Product Name Price");
System.out.println("== ============ =====");
ResultSet rs = stmt.executeQuery("select * from VQ1");
while (rs.next()){
System.out.println(rs.getString("PRODUCTID") + " " + rs.getString("PRODUCTNAME") + " " + rs.getString("UNITPRICE"));
}
rs.close();
}
}
例外情况发生在ResultSet rs = stmt.executeQuery("select * from VQ1")
就像我说的那样,我真的很擅长使用这种东西,所以它可能非常小而简单。
答案 0 :(得分:0)
你从未初始化stmt
- 它是空的。你错过了:
stmt = conn.createStatement();