Я интересуюсь проектом, использующим postgresql для Glassfish.Когда я выполняю выражение PreparedStatement pstmt = conn.prepareStatement(sql)
, оно дает мне исключение java.lang.NullPointerException.
Вот мой код:
String sql = "DELETE FROM blocklist WHERE ? >= time + ?;";
try(Connection conn = this.connect();
PreparedStatement pstmt = conn.prepareStatement(sql))
{
pstmt.setLong(1, System.currentTimeMillis());
pstmt.setLong(2, blocktime);
pstmt.executeUpdate();
}
catch(SQLException ex)
{
Logger.getLogger(RecordManager.class.getName()).log(Level.SEVERE, null, ex);
}
Здесь находится функция connect (), которая вызывается в Connection conn = this.connect();
:
private Connection connect()
{
Connection con = null;
try
{
con = DriverManager.getConnection(Config.dburl, Config.dbusername, Config.dbpassword);
}
catch(SQLException ex)
{
Logger.getLogger(RecordManager.class.getName()).log(Level.SEVERE, null, ex);
}
return con;
}
Вот журнал исключений:
Severe: Exception in thread "AWT-EventQueue-0"
Severe: java.lang.NullPointerException
at urrsm.sng.RecordManager.unblockrun(RecordManager.java:91)
at urrsm.sng.WebScocketEnd$1.actionPerformed(WebScocketEnd.java:45)
at javax.swing.Timer.fireActionPerformed(Timer.java:313)
at javax.swing.Timer$DoPostEvent.run(Timer.java:245)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)