我有一个简单的要求是在mysql数据库中获取timestampdifF并使用java代码中的resultset值来检查时间戳大于15分钟的条件,如果是,则在DB中进行一些更新,否则跳过并继续下一个流程
但是,当我在Java中传递结果集值时,我没有得到正确的值。直接在数据库上执行时,相同的查询返回正确的值。以下是我的代码片段:
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
String Diff = null;
try {
conn = Daofactory.getconnection();
String sql = "select TIMESTAMPDIFF(MINUTE,max(start_tstamp),NOW()) as timediff from app.process_log where status = 'P'";
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
while(rs.next()) {
log.info("Inside while loop");
Diff = rs.getString(1);
}
if(Diff.equalsIgnoreCase("15")) {
String sql1 = "update statement here";
stmt = conn.prepareStatement(sql1);
int i = stmt.executeUpdate();
}
当我直接在DB上执行查询时,它会以分钟为单位返回正确的值;但是,当我运行程序时,timeDiff始终为0.我该如何解决这个问题?