0
I’m doing a project in Java and I have a data base with two tables and one of them with a calculated field.
The calculated field is of type "time" and was done with the command
UPDATE nome_da_tabela SET Nome_do_campo = TIMEDIFF(hora2, hora1)
I have two Prepared statements in Java: one to insert and the other to make the calculated field, ie the Update.
Now, when I go to insert a record, in Java, in the table that has the calculated field and does not insert in the database. It gives an error to say:
"Field 'Fieldname' doesn’t have a default value"
Maybe if you recreate your field in the table, you can look at these Mysql links: https://dev.mysql.com/doc/refman/5.7/en/data-type-defaults.html and https://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html
– Paulo H. Hartmann
update without Where ? is to update in all records of the same table ? I believe that in this column at the time of your Insert, you should inform
null
, or even already perform the calculation at the time of the Insert...INSERT INTO .... (coluna_dif, ...) VALUES (TIMEDIFF(hora2, hora1), ... );
– Rovann Linhalis
update without Where, I know what this can entail. I have a bank with 1850 lyrics in Italian, Spanish, English and Brazilian versions totaling 7400 letters. I once went to update a lyric of a song and I did so: UPDATE all_pages_ordernada SET letra='". $letra_br." '); The rest you already know right. Be very careful with those forgetfulness!!!
– user60252
what it seems to me, it executes this 'calculation' to each Insert... unnecessary
– Rovann Linhalis
@Rovannlinhalis is to upgrade after the
INSERT
in this table. I can also make aPreparedStatement
in Java with the commandINSERT INTO..VALUES(TIMEDIFF(hora1, hora2....)
– Guilherme R
exactly... after each insert you perform an update, in the same table ? seems unnecessary to me
– Rovann Linhalis