データベース内で更新ステートメントを実行する次のメソッドを作成しました。
public boolean updateEmployee(int id){
try {
String update="UPDATE employee set name='updatedName' and address='updatedaddress' where id=(?)";
pst=connection.prepareStatement(update);
pst.setInt(1, id);
pst.executeUpdate();
} catch (SQLException ex) {
Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
return false;
}
return true;
}
ただし、次の例外が発生します。
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
そして、この例外もスローされます:
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: 'UpdatedName'
ここで何が問題なのですか?さらに、更新ステートメントの結果を返すにはどうすればよいですか ( executeQuery
DML ステートメントでは機能しないため)。