JAVA事务中的java.lang.NullPointerException
我从未在JAVA中使用过事务。我找到了一些例子,并试图以此为基础完成我的任务。我得到了NullPointerExection。这是代码。 我想插入到表中,并在插入后立即显示结果JAVA事务中的java.lang.NullPointerException,java,nullpointerexception,Java,Nullpointerexception,我从未在JAVA中使用过事务。我找到了一些例子,并试图以此为基础完成我的任务。我得到了NullPointerExection。这是代码。 我想插入到表中,并在插入后立即显示结果 static int InsertTicket(String Question,String Status,int priority, int CustomerID, int productID) throws SQLException { int nRowCount = 0; try {
static int InsertTicket(String Question,String Status,int priority, int CustomerID, int productID) throws SQLException {
int nRowCount = 0;
try {
con.setAutoCommit(false);
Statement strSQL1=null;
Statement strSQL2=null;
ResultSet strSQL2str=null;
strSQL1 = con.createStatement();
strSQL2 = con.createStatement();
nRowCount = strSQL1.executeUpdate("INSERT INTO dbs.Ticket (ticketID, Problem, Status, Priority,LoggedTime,CustomerID,ProductID) VALUES"
+"('"+Question+"', '"+Status+"','"+priority+"',current_timestamp, '"+CustomerID+"','"+productID+"')");
strSQL2str = strSQL2.executeQuery("SELECT * FROM dbs.Ticket WHERE ticketID=MAX(ticketID)");
con.commit();
con.setAutoCommit(true);
} catch (SQLException e){
try { con.rollback(); } catch (SQLException ex){
ex.printStackTrace();
}
throw e;
}
return nRowCount;
}
这里有什么问题?
感谢您抽出时间。推广以回答您的评论:
你是对的,我实际上使用的是“连接变量”,“con”是未使用的。多谢各位 啊,还有。。。NPE在哪里?来吧,堆栈跟踪会很好…只是一个猜测。。。我们没有初始化连接con?