[英]prepareStatement.executeUpdate(sql) giving error
當我嘗試使用准備好的語句更新 SQL 數據庫時,我不知道為什么我的代碼在executeUpdate(sql)
處出錯。 當我嘗試在 Oracle SQL 終端運行 SQL 查詢時,它工作得很好。 誰能幫幫我嗎。 我在下面添加了代碼。
我嘗試調試,但顯示錯誤
int iRs = cimStmt.executeUpdate(sql.toString());
public String updatePatternDiffRemarks(String sLot,
String sRemarks,
String sUserId,
int iLangMode)
{
StringBuffer sql = null;
Connection con = null;
PreparedStatement stmt = null;
StringBuffer rtnMsg = new StringBuffer("");
try {
con = CimDbConnect.getDbConnection();
if (con == null) {
throw new Exception("Failed DB connect.");
}
con.setAutoCommit(false);
sql = new StringBuffer();
sql.append(" UPDATE ");
sql.append(" CIM.PRODUCT_BPM_DIFF_COMMENT_TBL ");
sql.append(" SET REMARKS = ? ");
sql.append(" , LAST_MODIFIED_DATE = sysdate ");
sql.append(" , USER_ID = ? ");
sql.append(" WHERE ");
sql.append(" LOT_NO = ? ");
stmt = con.prepareStatement(sql.toString());
CimPreparedStatement cimStmt = new CimPreparedStatement(stmt);
int index = 1;
cimStmt.setString(index++, sRemarks);
cimStmt.setString(index++, sUserId);
cimStmt.setString(index++, sLot);
int iRs = cimStmt.executeUpdate(sql.toString());
con.commit();
} catch(ClassNotFoundException e) {
e.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
rtnMsg = CimMessage.setMsgStyleCForHtml(rtnMsg, e.getMessage(), false);
CimMessage.putErrMsgEx(e, this.getClass().getName() + ": updatePatternDiffRemarks Exception!!");
if(con != null) {
try {
con.rollback();
} catch(Exception ex) {
ex.printStackTrace();
}
}
} finally {
try {
if(stmt != null) {
stmt.close();
}
if(con != null) {
con.close();
}
} catch(Exception e) {
CimMessage.putErrMsgEx(e, this.getClass().getName() + ": updatePatternDiffRemarks Exception!!");
}
}
return rtnMsg.toString();
}
你能嘗試像這個例子那樣使用分離的嗎:
public void closeConn(PreparedStatement ps) throws SQLException {
if (ps != null) {
ps.close();
}
}
public void updateService(Servs srv){
String sql = "UPDATE services SET name=?, description =? , content = ? , img = ? WHERE id = ? ";
PreparedStatement ps = null;
try{
ps = super.prepareStatement(sql);
ps.setString(1, srv.getName());
ps.setString(2, srv.getDescription());
ps.setString(3, srv.getContent());
ps.setString(4, srv.getImg());
ps.setInt(5, srv.getId());
ps.execute();
}catch(SQLException|NullPointerException e){
logger.error("Error UPDATE >> ",e);
}
finally {
closeCn(ps);
}
}// CRUD UPDATE
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.