Skip to content Skip to sidebar Skip to footer

On Duplicate Key Update Feature In H2

I have developed java desktop application with the use of H2(Embedded). I just have basic knowledge about database, so i simply installed H2 and create a schema name RecordAutomati

Solution 1:

You need to use the MySQL mode. To do that, append ;mode=MySQL to the database URL. (This feature is not properly documented yet).

The table needs to have a primary key or at least a unique index. Complete example:

droptable MREPORT;

set mode MySQL;

createtable MREPORT(PRODUCTID intprimary key, 
DESCRIPTION varchar, QUANTITY int,  SUBTOTAL int, PROFIT int);

INSERTINTO MREPORT 
(PRODUCTID ,DESCRIPTION ,QUANTITY ,SUBTOTAL ,PROFIT ) 
VALUES (22,'olper',5,100,260) 
ON DUPLICATE KEY UPDATE QUANTITY = QUANTITY+5;

Post a Comment for "On Duplicate Key Update Feature In H2"