简体   繁体   中英

SQLite for Java not updating rows correctly

Good afternoon. I've got a problem with my DB implementing it on Java. I want to update these two columns. The row Puntos doesn't occasionate any kind of problem, and every time I run the executeUpdate(), the row gets incremented. However, in 'Victorias totales', the executeUpdate() method behaves as if it was just like

UPDATE EquiposIBAI 
SET Puntos=Puntos + 3, 'Victorias Totales' = 1 
WHERE NOMBRE='SD Eibar' AND fk_CodLiga=5;

I mean, the value doesn't get incremented, it gets just overwritten.

UPDATE EquiposIBAI 
SET Puntos=Puntos + 3, 'Victorias Totales' = 'Victorias Totales' + 1 
WHERE NOMBRE='SD Eibar' AND fk_CodLiga=5;

Is there any way to fix it?(I'm using SQLite for Java) Thx in advance.

In SQLite you need to escape column names using either double quotes ( " ), square brackets ( [] ), or back ticks.

I would use the double quotes for simplicity (it's the standard SQL way), as in:

UPDATE EquiposIBAI 
SET Puntos=Puntos + 3, "Victorias Totales" = "Victorias Totales" + 1 
WHERE NOMBRE='SD Eibar' AND fk_CodLiga=5;

Single quotes are for string literals, and they are well used in the third line.

Alternatively, I would avoid (when possible) to use spaces in column names, or well... any special character for that matter. In this case, I would change the column name to victorias_totales .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM