所以我有這個代碼應該提供給我一行的id。java sql的語法錯誤選擇
public int getIdSala(Connection conn, String t) {
try {
String query = "Select id_sala from sala where nume = ?";
PreparedStatement st = conn.prepareStatement(query);
st.setString(1, t);
ResultSet rs = st.executeQuery(query);
id = rs.getInt("Id_sala");
} catch (Exception e) {
System.err.println("Got an exception!");
System.err.println(e.getMessage());
}
return id;
}
而且我得到以下錯誤:
You have an error in your SQL syntax; check the manual that corresponds to your MySQLserver version for the right syntax to use near '?' at line 1
可能是什麼問題呢?
什麼數據庫?什麼JDBC驅動程序? – bmargulies