-2
我在做預訂程序。JDBC錯誤。幫我
我面臨MySQL JDBC錯誤。
我執行了下面的代碼。
public void ReservationModifyQuery(String room, String name, String phone, String nop, String revdate, String revtime, String usetime, String isgroup, String id, String PrefRoom, String PrefReservationTime, String PrefDateString, Connection conn) throws Exception{
String updateDB = "UPDATE reservation SET ";
String sql = "roomNum = ?,"+
"Name = ? ,"+
"Phone = ? ,"+
"NumOfPeople = ? ,"+
"ReservationDate = ? ,"+
"ReservationTime = ? ,"+
"UseTime = ? ,"+
"Group = ? ,"+
"ID = ? ";
sql = "roomNum = ?";
String where = "where roomNum = ? and ReservationDate = ? and ReservationTime = ? ;";
pstmt = conn.prepareStatement(updateDB+sql+where);
pstmt.setInt(1, Integer.parseInt(room));
pstmt.setInt(2, Integer.parseInt(PrefRoom));
pstmt.setDate(3, Date.valueOf(PrefDateString));
pstmt.setTime(4, Time.valueOf(PrefReservationTime));
pstmt.executeUpdate();
sql = "Name = ?";
pstmt = conn.prepareStatement(updateDB+sql+where);
pstmt.setString(1, name);
pstmt.setInt(2, Integer.parseInt(PrefRoom));
pstmt.setDate(3, Date.valueOf(PrefDateString));
pstmt.setTime(4, Time.valueOf(PrefReservationTime));
pstmt.executeUpdate();
sql = "Phone = ?";
pstmt = conn.prepareStatement(updateDB+sql+where);
pstmt.setString(1, phone);
pstmt.setInt(2, Integer.parseInt(PrefRoom));
pstmt.setDate(3, Date.valueOf(PrefDateString));
pstmt.setTime(4, Time.valueOf(PrefReservationTime));
pstmt.executeUpdate();
sql = "NumOfPeople = ?";
pstmt = conn.prepareStatement(updateDB+sql+where);
pstmt.setInt(1, Integer.parseInt(nop));
pstmt.setInt(2, Integer.parseInt(PrefRoom));
pstmt.setDate(3, Date.valueOf(PrefDateString));
pstmt.setTime(4, Time.valueOf(PrefReservationTime));
pstmt.executeUpdate();
sql = "ReservationDate = ?";
pstmt = conn.prepareStatement(updateDB+sql+where);
pstmt.setDate(1, Date.valueOf(revdate));
pstmt.setInt(2, Integer.parseInt(PrefRoom));
pstmt.setDate(3, Date.valueOf(PrefDateString));
pstmt.setTime(4, Time.valueOf(PrefReservationTime));
pstmt.executeUpdate();
sql = "ReservationTime = ?";
pstmt = conn.prepareStatement(updateDB+sql+where);
pstmt.setTime(1, Time.valueOf(revtime));
pstmt.setInt(2, Integer.parseInt(PrefRoom));
pstmt.setDate(3, Date.valueOf(PrefDateString));
pstmt.setTime(4, Time.valueOf(PrefReservationTime));
pstmt.executeUpdate();
sql = "UseTime = ?";
pstmt = conn.prepareStatement(updateDB+sql+where);
pstmt.setDouble(1, Double.parseDouble(usetime));
pstmt.setInt(2, Integer.parseInt(PrefRoom));
pstmt.setDate(3, Date.valueOf(PrefDateString));
pstmt.setTime(4, Time.valueOf(PrefReservationTime));
pstmt.executeUpdate();
sql = "Group = ?";
pstmt = conn.prepareStatement(updateDB+sql+where);
pstmt.setString(1, isgroup);
pstmt.setInt(2, Integer.parseInt(PrefRoom));
pstmt.setDate(3, Date.valueOf(PrefDateString));
pstmt.setTime(4, Time.valueOf(PrefReservationTime));
pstmt.executeUpdate();
sql = "ID = ?";
pstmt = conn.prepareStatement(updateDB+sql+where);
pstmt.setString(1, id);
pstmt.setInt(2, Integer.parseInt(PrefRoom));
pstmt.setDate(3, Date.valueOf(PrefDateString));
pstmt.setTime(4, Time.valueOf(PrefReservationTime));
pstmt.executeUpdate();
pstmt.close();
conn.close();
}
此代碼出現在下面的語法異常。 但我不知道錯誤節...
我該如何解決這個問題?
你讓兩個賦值在開始'sql'變量。這是你真正想做的嗎? – Nurjan
請在你的問題中包含完整的stacktrace作爲** text **,不要將圖像用於可以通過文本傳遞的內容。順便說一句:這個問題可能是串聯後'''和'WHERE'之間的空白。 –