简体   繁体   中英

Java Update Sql statement error

I am trying to update a Db2 database using Java and the following code:

String sSqlString = "UPDATE P6DEVCDB00.P6OSTAPF SET STATVAL = '" + sStatVal + "' WHERE  OPIID = '" + sOperationsitemid + "' AND CONGRPC = '" + sConfigGrpCode  + "'";

// Do your select on a Db table.
//statement = con.createStatement();
statement = con.prepareStatement(sSqlString);

int RowsAffected = statement.executeUpdate();
con.commit();
System.out.println(RowsAffected);

I then get the following error :

DB2 SQL Error: SQLCODE=-7008, SQLSTATE=55019, SQLERRMC=P6OSTAPF  ;
P6DEVCDB00;3, DRIVER=3.58.81

I have printed out the sql that it's going to run :

UPDATE  P6DEVCDB00.P6OSTAPF SET STATVAL = 'ON' 
WHERE   OPIID = 'B20120707000681531' AND CONGRPC = 'STKLSTSTAT

When I run this sql directly with a SQLUI tool it works and the record gets updated...

Your problem is that you're attempting to use transactions over tables that are not 'journaled' - that is, setup for transactions.

Ideally, you should set up all tables (that will be run under a transaction) as journaled, specifically to test that property ; regardless of being able to simulate failures, you need to make sure that your code can handle being under transactions.
Also, depending on your situation, you may not need to explicitly manage transactions. If you're using a framework like Spring , they can usually manage transactions for you, although this will usually mean that you still need journaling on your iSeries tables.

If you're just trying to test basic code behavior, look into using an in-memory database, such as HSQLDB (can emulate some LUW DB2 behavior, but not library lists, unfortunately) - this will absolve you of the need to have a connection to your box, and to set up journaling.

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