我的SQLServer中有以下查询。
update time_tracker
set logout = '08-11-2016 17:28:02', totaltime = DATEDIFF(minute,login, logout)
from Time_Tracker
where userid = 0138039 AND CONVERT(Date, LOGIN) = CONVERT(Date, GETDATE())
在我的JDBC中,我采取了以下查询
Date endDate = new Date();
DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");
String logoutTime = dateFormat.format(endDate);
System.out.println(logoutTime);
String sql =
"update time_tracker " +
"set logout = ?, totaltime = DATEDIFF(minute,login, logout) " +
"from Time_Tracker " +
"where userid= ? AND CONVERT(Date, LOGIN) = CONVERT(Date, GETDATE())";
preparedStatement = conn.prepareStatement(sql);
preparedStatement.setString(1, logoutTime);
preparedStatement.setString(2, userId);
preparedStatement.execute();
preparedStatement.close();
当我运行这个程序时,我的后端没有完成更新,但是当我直接在我的SQL Server中运行查询时,它运行正常。请让我知道我哪里出错了,我该怎么办呢。
由于
答案 0 :(得分:1)
我想你可以改变跟随: 在PreparedStatement.executeUpdate();