Field calculated in Java

Asked

Viewed 139 times

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

  • 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), ... );

  • 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!!!

  • what it seems to me, it executes this 'calculation' to each Insert... unnecessary

  • @Rovannlinhalis is to upgrade after the INSERT in this table. I can also make a PreparedStatementin Java with the command INSERT INTO..VALUES(TIMEDIFF(hora1, hora2....)

  • exactly... after each insert you perform an update, in the same table ? seems unnecessary to me

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.