Check whether the primary key exists in the table.
If exists retrieve three column values and update the three column values with new values.
String sql = "SELECT brno, brdate, type1,type,flag,mcode,pamount,tax,pamount1,liab FROM rawdata WHERE mcode="+mcode; ResultSet rs = statement.executeQuery(sql); rs.first(); float oldPamount= rs.getFloat("pamount"); float tax= rs.getFloat("tax"); float oldPamount1= rs.getFloat("pamount1"); float newPamount= pamount; float newTax= tax; float newPamount1= pamount1; rs.updateFloat("pamount", newPamount); rs.updateFloat("tax", newTax); rs.updateFloat("pamount1", newPamount1); rs.updateRow();
If not exists insert the record and retrieve it. I have tried this:
INSERT INTO rawdata (brno, brdate, type1,type,flag,mcode,pamount,tax,pamount1,liab) SELECT * FROM (SELECT '1', '02.05.15', 'G','H','E','2222','789.00','0.00','789.00','L') AS tmp WHERE NOT EXISTS ( SELECT mcode FROM rawdata WHERE mcode = '2222' );
But it getting the following error duplicate value 789.00
I need to done these things at a time not separate queries.
This is my table(rawdata) with fields(brno, brdate, type1,type,flag,mcode,pamount,tax,pamount1,liab) where mcode is the primarykey
Here the pamount,tax,pamount1 need to be updated if the record exists.
For Ex:
These are the sample values 873.00,0.00,873.00
needed to be updated to 789.00,0.00,789.00
(or) 24000.00,240.00,23760.00
Other wise need to insert entire row for the new mcode
I have tried the above queries, but i need to be done at time.