我的代码停止工作,发生了这种错误
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at ultimate_library.unified.showAll(unified.java:47)
at ultimate_library.unified.<init>(unified.java:34)
at ultimate_library.unified$8.run(unified.java:653)
下面的代码没有任何错误,我只是不明白它是否工作,但有时它工作但它发送此错误“java.sql.SQLTransactionRollbackException:在请求的时间内无法获得锁”
public unified() {
initComponents();
DoConnect();
showAll();
DoConnect2();
showAll2();
}
void showAll(){
try{
rss = stmt.executeQuery("SELECT * FROM accounts");
while(rss.next())
{
String name = rss.getString("name");
String email = rss.getString("email");
String bdays = rss.getString("bday");
loginModel.addRow(new Object[]{name, email, bdays});
}
}catch(SQLException err){
System.out.println(err);
}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new unified().setVisible(true);
}
});
}
答案 0 :(得分:0)
我发现了我的错误,而不是rss,我将其替换为rs2。
void showAll(){
try{
rs2 = stmt.executeQuery("SELECT * FROM accounts");
while(rs2.next())
{
String named = rs2.getString("name");
String emailss = rs2.getString("email");
String bdayss = rs2.getString("birthday");
loginModel.addRow(new Object[]{named, emailss, bdayss});
}
}catch(SQLException err){
System.out.println(err);
}
}