我的程序中有update()api,如果我更改了某些内容,则在其中进行了insertHistory()api的调用。 我想让我的程序像任何字段都发生更改一样,然后仅insertHistory()进行调用,否则不进行。
我的目的是当用户在编辑页面上不执行任何操作并单击“保存”按钮时,更新方法将不运行。
我对update()的原始编程是这样的:
public static boolean updateDetails(StudentSVO svo, Connection con, AppLogger logger) {
boolean returnValue = true;
PreparedStatement ps = null;
StringBuffer updateQuery = new StringBuffer();
updateQuery.append("\nUPDATE STUDENT_DETAIL SET NAME = ? ,ROLL_NO = ? ,LAST_UPDATED_BY = ? ,LAST_UPDATED_ON = ? WHERE ID = ? ");
updateQuery.append("\n ");
try {
VocMasterSVO currentSVO = getById(svo.getId(), con, logger);
if(currentSVO!=null){
insertHistory(currentSVO, con, logger);
}
ps = con.prepareStatement(updateQuery.toString());
ps.setInt(DBManager.RS_INDEX_1, svo.getName());
ps.setInt(DBManager.RS_INDEX_2, svo.getRollNo());
ps.setInt(DBManager.RS_INDEX_3, svo.getLastUpdatedBy());
ps.setLong(DBManager.RS_INDEX_4, svo.getLastUpdatedOn());
ps.setInt(DBManager.RS_INDEX_5, svo.getId());
ps.executeUpdate();
} catch (SQLException ex) {
logger.error("Exception occured in updateDetails method:" + ex, ex);
return false;
} catch (Exception ex) {
logger.error("Exception occured in updateDetails method:" + ex, ex);
return false;
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (Exception ex) {}
}
return returnValue;
}
我尝试过:
public static boolean updateDetails(StudentSVO svo, Connection con, AppLogger logger) {
boolean returnValue = true;
PreparedStatement ps = null;
StringBuffer updateQuery = new StringBuffer();
updateQuery.append("\nUPDATE STUDENT_DETAIL SET NAME = ? ,ROLL_NO = ? ,LAST_UPDATED_BY = ? ,LAST_UPDATED_ON = ? WHERE ID = ? ");
updateQuery.append("\n ");
try {
StudentSVO currentSVO = getById(svo.getId(), con, logger);
if(currentSVO!=null){
if(!currentSVO.getName().equalsIgnoreCase(svo.getName()) || currentSVO.getRollNo()!=svo.getRollNo() ) {
ps = con.prepareStatement(updateResolutionDetailsQuery.toString());
ps.setInt(DBManager.RS_INDEX_1, svo.getName());
ps.setInt(DBManager.RS_INDEX_2, svo.getRollNo());
ps.setInt(DBManager.RS_INDEX_3, svo.getLastUpdatedBy());
ps.setLong(DBManager.RS_INDEX_4, svo.getLastUpdatedOn());
ps.setInt(DBManager.RS_INDEX_5, svo.getId());
ps.executeUpdate();
insertHistory(currentSVO, con, logger);
}
} catch (SQLException ex) {
logger.error("Exception occured in updateDetails method:" + ex, ex);
return false;
} catch (Exception ex) {
logger.error("Exception occured in updateDetails method:" + ex, ex);
return false;
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (Exception ex) {}
}
return returnValue;
}
有什么建议吗?