Error inserting timestamp

1

I have the following sentence ready ...

  

Query to insert TimeStamp

 public void insertarValores() throws SQLException{
    PreparedStatement ps = null;
    conectar con = new conectar();
    Connection conn = null;
    conn = con. conectar();  
    try{
        java.sql.Date sqlDate = java.sql.Date.valueOf(ldt.toLocalDate());
        ps = conn.prepareStatement(SQL_INSERT);
        ps.setString(1, user_dto.getId_usuario());
        ps.setString(2, instdDto.getId_instituto());
        ps.setString(3, dto.getT1_A_A());
        .
        .
        .
        ps.setTimestamp(39, getCurrentTimeStamp());
        ps.executeUpdate();
    }catch(SQLException e){
        System.err.println(""+e);
    }finally{
        cerrar(ps);
        cerrar(conn);

    }
} 


private static java.sql.Timestamp getCurrentTimeStamp() {

java.util.Date today = new java.util.Date();
return new java.sql.Timestamp(today.getTime());

}

When running, the following SQLException appears:

com.microsoft.sqlserver.jdbc.SQLServerException: No se puede insertar un valor explícito en una columna de marca de tiempo. Utilice INSERT con una lista de columnas para excluir la columna de marca de tiempo o inserte DEFAULT en la columna de marca de tiempo.
    
asked by runjavcos 22.09.2018 в 00:24
source

1 answer

2

Reviewing the documentation of the timestamp fields, it turns out that you can not make changes to the records directly, as they work as a "rowversion". If you want to use a date field use date or datetime , otherwise, in the structure of the table define the timestamp with a default .

Reference: timestamp

    
answered by 22.09.2018 / 00:56
source