因此,這裏是我的代碼我無法從Java更新SQL DATETIME,但插入正常工作
java.sql.Timestamp date =
new java.sql.Timestamp(new java.util.Date().getTime());
java.text.SimpleDateFormat sdf =
new java.text.SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
String currentTime = sdf.format(date)
int abs=0;
Statement tgl = connect.createStatement();
ResultSet rs = tgl.executeQuery("SELECT id_absensi FROM absensi ORDER BY id_absensi DESC LIMIT 1");
while (rs.next()){
abs=rs.getInt("id_absensi");
}
String query = "UPDATE absensi SET tgl_keluar ="
+ currentTime
+ " WHERE 'id_absensi'=" + abs ;
Statement aa = connect.createStatement();
int bb = aa.executeUpdate(query);
的問題是,當我嘗試運行此我得到這個通知
融爲一體。 mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL語法中有一個 錯誤;檢查對應於您 MariaDB的服務器版本正確的語法附近'01使用手冊:其中「id_absensi」 = 1' 在行1
我知道這應該是一個簡單的語法35 :59錯誤但我不知道哪一個?我甚至試圖複製實際的mysql語句更新 PS。選擇不是問題,只是更新。
請幫
您應該使用'preparedStatements'一... –