You doubt with a PreparedStatement that executes an UPDATE

0

I have this PreparedStatement , I would like to know if it is correct, I would also like to know if you have to create a method to do EXECUTE , or in the same method of PreparedStatement of UPDATE .

public void Modify(int id_estado_operacion, Date fechaHora_publicacion,  Date audit_fechaHora_ultima_modificacion, int id_publicacion) {
  Connection connection = null;
  PreparedStatement prepareStmt = null;

  try{
      String query = "update publicaciones set id_estado_operacion,"
            + "fechaHora_publicacion=?, "
            + "adudit_fechaHora_ultima_modificacion=GETDATE() "
            + "where id_publicacion = ? ";

      prepareStmt.setInt(0,id_estado_operacion);
      prepareStmt.setDate(1,fechaHora_publicacion);
      prepareStmt.setDate(2,audit_fechaHora_ultima_modificacion );
      prepareStmt.setInt(3,id_publicacion);
      prepareStmt.executeUpdate();
  } catch (SQLException e) {
      System.out.println(e.getMessage());
  }
}
    
asked by NymHaRI 15.08.2017 в 22:33
source

1 answer

1

The problem is that JDBC works with indexes based on 1, not 0. The parameters should be set from index 1.

Your code should change to this:

prepareStmt.setInt(1,id_estado_operacion);
prepareStmt.setDate(2,fechaHora_publicacion);
prepareStmt.setDate(3,audit_fechaHora_ultima_modificacion );
prepareStmt.setInt(4,id_publicacion);
prepareStmt.executeUpdate();
    
answered by 15.08.2017 в 22:36