jjzjj

java - 通过JBDC获取在IBM DB2 V6R1 (AS400)上插入的行数

coder 2024-03-20 原文

我们最近迁移到 AS400 上较新的 V6R1 版本的 DB2,我们使用 Spring 框架(v. 2.5.6.)与数据库通信。我们正在调用 Spring 的 NamedParameterJdbcTemplate.update() 方法来插入新行,这个方法应该返回插入行的数量,但没有发生什么(结果我们得到零返回)虽然行被定期插入.

我们得出的结论是,如果insert语句中没有主键列,一切正常,所以PK列自增时没有问题,但在某些情况下我们必须插入PK值,然后我们必须以某种方式应对定期出现的情况插入的行未在 JDBC 或 Spring 中注册。

有人可以帮忙吗?

最佳答案

更新:这个issue已修复 JTOpen 7.6


我和 Ante 一起工作......这个问题与 Spring 无关,这是肯定的,因为我已经建立了一个使用普通 JDBC 和 PreparedStatements 的项目。

所以我将添加更多信息来模拟问题:

数据链接:

CREATE TABLE TEST_V6R1 (
        ID INTEGER NOT NULL DEFAULT,
        VALUE VARCHAR(50)
    );

ALTER TABLE TEST_V6R1 ADD CONSTRAINT TEST_V6R1_PK PRIMARY KEY
    (ID);

SQL:

insert into test_v6r1 (id, value ) values (?, ?)

Java代码:

public class TestV6R1 {

   public static void main( String[] args ) {
      Connection conn = null;
      PreparedStatement ps1 = null;
      PreparedStatement ps2 = null;
      try {
         conn = getNewConnection();
         conn.setAutoCommit( false );

         String value = "Test: " + new Timestamp( System.currentTimeMillis() );

         // First statement which uses RETURN_GENERATED_KEYS
         ps1 = conn.prepareStatement( "insert into test_v6r1 (id, value ) values (?, ?)", Statement.RETURN_GENERATED_KEYS );
         ps1.setInt( 1, 1 );
         ps1.setString( 2, value );
         int ps1Rows = ps1.executeUpdate();
         // in case of V5R4
         // ps1Rows is 1
         // in case of V6R1
         // ps1Rows is 0

         ResultSet ps1keys = ps1.getGeneratedKeys();
         int ps1KeySize = 0;
         if (ps1keys != null) {
            ps1keys.last();
            ps1KeySize = ps1keys.getRow();
         }
         System.out.println("PS1 - SQL insert affected " + ps1Rows + " rows and returned " + ps1KeySize + " keys");
         System.out.println("PS1 - getUpdateCount()="+ ps1.getUpdateCount());

         // Second statement which uses NO_GENERATED_KEYS
         ps2 = conn.prepareStatement( "insert into test_v6r1 (id, value) values (?, ?)", Statement.NO_GENERATED_KEYS );
         ps2.setInt( 1, 2 );
         ps2.setString( 2, value );
         int ps2Rows = ps2.executeUpdate();
         // in case of V5R4
         // ps2Rows is 1
         // in case of V6R1
         // ps2Rows is 1

         ResultSet ps2Keys = ps2.getGeneratedKeys();
         int ps2KeySize = 0;
         if (ps2Keys != null) {
            ps2Keys.last();
            ps2KeySize = ps2Keys.getRow();
         }

         System.out.println("PS2 - SQL insert affected " + ps2Rows + " rows and returned " + ps2KeySize + " keys");
         System.out.println("PS2 - getUpdateCount()="+ ps2.getUpdateCount());

         conn.commit();
      }
      catch ( Throwable e ) {

         e.printStackTrace();
         try {
            conn.rollback();
         }
         catch ( SQLException e1 ) {
            e1.printStackTrace();
         }
      }
      finally {
         try {
            if (ps1!=null) ps1.close();
            if (ps2!=null) ps2.close();
            if (conn!=null) conn.close();
         }
         catch ( SQLException e ) {
            e.printStackTrace();
         }
      }

   }

   public static Connection getNewConnection() {
      try {
         Class.forName( "com.ibm.as400.access.AS400JDBCDriver" ); // Or any other driver
      }
      catch ( Exception x ) {
         System.out.println( "Unable to load the driver class!" );
      }
      Connection dbConnection = null;
      try {
         // TEST - V6R1
         dbConnection = DriverManager
               .getConnection( "jdbc:as400://testServer;libraries=*libl;naming=system;sort=language;sort language=HRV;sort weight=shared;prompt=false;trace=true",
                               "username",
                               "password" );
         // PRODUCTION - V5R4
//         dbConnection = DriverManager
//         .getConnection( "jdbc:as400://productionServer;libraries=*libl;naming=system;sort=language;sort language=HRV;sort weight=shared;prompt=false;trace=true",
//                         "username",
//                         "password" );

      }
      catch ( SQLException x ) {
         System.out.println( "Couldn’t get connection!" );
      }

      return dbConnection;
   }

}

V5R4 控制台输出:

Toolbox for Java - Open Source Software, JTOpen 7.3, codebase 5770-SS1 V7R1M0.03 2011/01/14 @B5
as400: Properties  (12122347) : access = "all".
as400: Properties  (12122347) : block size = "32".
as400: Properties  (12122347) : block criteria = "2".
as400: Properties  (12122347) : date format = "".
as400: Properties  (12122347) : date separator = "".
as400: Properties  (12122347) : decimal separator = "".
as400: Properties  (12122347) : errors = "basic".
as400: Properties  (12122347) : extended dynamic = "false".
as400: Properties  (12122347) : libraries = "*libl".
as400: Properties  (12122347) : naming = "system".
as400: Properties  (12122347) : package = "".
as400: Properties  (12122347) : package add = "true".
as400: Properties  (12122347) : package cache = "false".
as400: Properties  (12122347) : package clear = "false".
as400: Properties  (12122347) : package error = "warning".
as400: Properties  (12122347) : package library = "".
as400: Properties  (12122347) : password = "".
as400: Properties  (12122347) : prefetch = "true".
as400: Properties  (12122347) : prompt = "false".
as400: Properties  (12122347) : remarks = "system".
as400: Properties  (12122347) : sort = "language".
as400: Properties  (12122347) : sort language = "HRV".
as400: Properties  (12122347) : sort table = "".
as400: Properties  (12122347) : sort weight = "shared".
as400: Properties  (12122347) : time format = "".
as400: Properties  (12122347) : time separator = "".
as400: Properties  (12122347) : trace = "true".
as400: Properties  (12122347) : transaction isolation = "read uncommitted".
as400: Properties  (12122347) : translate binary = "false".
as400: Properties  (12122347) : user = "username".
as400: Properties  (12122347) : package criteria = "default".
as400: Properties  (12122347) : lob threshold = "32768".
as400: Properties  (12122347) : secure = "false".
as400: Properties  (12122347) : data truncation = "true".
as400: Properties  (12122347) : proxy server = "".
as400: Properties  (12122347) : secondary URL = "".
as400: Properties  (12122347) : data compression = "true".
as400: Properties  (12122347) : big decimal = "true".
as400: Properties  (12122347) : thread used = "true".
as400: Properties  (12122347) : cursor hold = "true".
as400: Properties  (12122347) : lazy close = "false".
as400: Properties  (12122347) : driver = "toolbox".
as400: Properties  (12122347) : bidi string type = "5".
as400: Properties  (12122347) : key ring name = "".
as400: Properties  (12122347) : key ring password = "".
as400: Properties  (12122347) : full open = "false".
as400: Properties  (12122347) : server trace = "0".
as400: Properties  (12122347) : database name = "".
as400: Properties  (12122347) : extended metadata = "false".
as400: Properties  (12122347) : cursor sensitivity = "asensitive".
as400: Properties  (12122347) : behavior override = "0".
as400: Properties  (12122347) : package ccsid = "13488".
as400: Properties  (12122347) : minimum divide scale = "0".
as400: Properties  (12122347) : maximum precision = "31".
as400: Properties  (12122347) : maximum scale = "31".
as400: Properties  (12122347) : translate hex = "character".
as400: Properties  (12122347) : toolbox trace = "".
as400: Properties  (12122347) : qaqqinilib = "".
as400: Properties  (12122347) : login timeout = "".
as400: Properties  (12122347) : true autocommit = "false".
as400: Properties  (12122347) : bidi implicit reordering = "true".
as400: Properties  (12122347) : bidi numeric ordering = "false".
as400: Properties  (12122347) : hold input locators = "true".
as400: Properties  (12122347) : hold statements = "false".
as400: Properties  (12122347) : rollback cursor hold = "false".
as400: Properties  (12122347) : variable field compression = "true".
as400: Properties  (12122347) : query optimize goal = "0".
as400: Properties  (12122347) : keep alive = "".
as400: Properties  (12122347) : receive buffer size = "".
as400: Properties  (12122347) : send buffer size = "".
as400: Properties  (12122347) : XA loosely coupled support = "0".
as400: Properties  (12122347) : translate boolean = "true".
as400: Properties  (12122347) : metadata source = "-1".
as400: Properties  (12122347) : query storage limit = "-1".
as400: Properties  (12122347) : decfloat rounding mode = "half even".
as400: Properties  (12122347) : autocommit exception = "false".
as400: Properties  (12122347) : auto commit = "true".
as400: Properties  (12122347) : ignore warnings = "".
as400: Properties  (12122347) : secure current user = "true".
as400: Properties  (12122347) : concurrent access resolution = "0".
as400: Properties  (12122347) : jvm16 synchronize = "true".
as400: Properties  (12122347) : socket timeout = "".
as400: Properties  (12122347) : use block update = "false".
as400: Properties  (12122347) : maximum blocked input rows = "32000".
as400: Driver AS/400 Toolbox for Java JDBC Driver (15779934) : Using IBM Toolbox for Java JDBC driver implementation.
as400: Properties  (12122347) : metadata source = "0".
as400: Toolbox for Java - Open Source Software, JTOpen 7.3, codebase 5770-SS1 V7R1M0.03 2011/01/14 @B5
as400: JDBC Level: 40
as400: Properties  (12122347) : package ccsid = "13488".
as400: Connection productionServer (367156) : Client CCSID = 13488.
as400: Connection productionServer (367156) : Setting server NLV = 2912.
as400: Connection productionServer (367156) : Client functional level = V7R1M01   .
as400: Connection productionServer (367156) : Data compression = RLE.
as400: Connection productionServer (367156) : ROWID supported = true.
as400: Connection productionServer (367156) : True auto-commit supported = true.
as400: Connection productionServer (367156) : 128 byte column names supported = true.
as400: Connection productionServer (367156) : Maximum decimal precision = 31.
as400: Connection productionServer (367156) : Maximum decimal scale = 31.
as400: Connection productionServer (367156) : Minimum divide scale = 0.
as400: Connection productionServer (367156) : Translate hex = character.
as400: Connection productionServer (367156) : query optimize goal = 0.
as400: Connection productionServer (367156) : Using extended datastreams.
as400: Connection productionServer (367156) : JDBC driver major version = 9.
as400: Connection productionServer (367156) : IBM i VRM = V5R4M0.
as400: Connection productionServer (367156) : Server CCSID = 870.
as400: Connection productionServer (367156) : Server functional level = V5R4M00014 (14).
as400: Connection productionServer (367156) : Server job identifier = 692621/QUSER/QZDASOINIT.
as400: Properties  (12122347) : decimal separator = ".".
as400: Properties  (12122347) : date format = "dmy".
as400: Properties  (12122347) : date separator = "/".
as400: Properties  (12122347) : time format = "hms".
as400: Properties  (12122347) : time separator = ":".
as400: Connection productionServer (367156)  open.
as400: Connection productionServer (367156) : Auto commit = "true".
as400: Connection productionServer (367156) : Read only = "false".
as400: Connection productionServer (367156) : Transaction isolation = "1".
as400: Connection productionServer (367156) : Auto commit = "false".
as400: PreparedStatement STMT0001 (24864323)  open. Parent: Connection productionServer (367156) .
as400: PreparedStatement STMT0001 (24864323) : Escape processing = "true".
as400: PreparedStatement STMT0001 (24864323) : Fetch direction = "1000".
as400: PreparedStatement STMT0001 (24864323) : Fetch size = "0".
as400: PreparedStatement STMT0001 (24864323) : Max field size = "0".
as400: PreparedStatement STMT0001 (24864323) : Max rows = "0".
as400: PreparedStatement STMT0001 (24864323) : Query timeout = "0".
as400: PreparedStatement STMT0001 (24864323) : Result set concurrency = "1007".
as400: PreparedStatement STMT0001 (24864323) : Result set holdability = "1".
as400: PreparedStatement STMT0001 (24864323) : Result set type = "1003".
as400: PreparedStatement STMT0001 (24864323) : Behavior Override = "0".
as400: PreparedStatement STMT0001 (24864323) : Data to correlate statement with cursor Cursor CRSR0001 (7792807) .
as400: PreparedStatement STMT0001 (24864323) : Preparing [insert into test_v6r1 (id, value ) values (?, ?)].
as400: PreparedStatement STMT0001 (24864323) : Prepared STMT0001*, SQL Statement -->[insert into test_v6r1 (id, value ) values (?, ?)].
as400: PreparedStatement STMT0001 (24864323) : setInt().
as400: PreparedStatement STMT0001 (24864323) : parameter index: 1 value: 1.
as400: PreparedStatement STMT0001 (24864323) : setString().
as400: PreparedStatement STMT0001 (24864323) : parameter index: 2 value: Test: 2011-04-27 16:34:30.981.
as400: PreparedStatement STMT0001 (24864323) : Descriptor 1 created or changed.
as400: PreparedStatement STMT0001 (24864323) : returnCode is: 0.
as400: PreparedStatement STMT0001 (24864323) : generated key from system is: null.
as400: ResultSet  (2850225)  open.
as400: ResultSet  (2850225) : Conncurrency = "1007".
as400: ResultSet  (2850225) : Fetch direction = "1000".
as400: ResultSet  (2850225) : Fetch size = "0".
as400: ResultSet  (2850225) : Max rows = "0".
as400: ResultSet  (2850225) : Type = "1004".
as400: PreparedStatement STMT0001 (24864323) : Executed STMT0001*, SQL Statement --> [insert into test_v6r1 (id, value ) values (?, ?)].
as400: PreparedStatement STMT0001 (24864323) : Update count = 1.
as400: PreparedStatement STMT0001 (24864323) : Result set = false.
as400: PreparedStatement STMT0001 (24864323) : Number of result sets = 0.
as400: PreparedStatement STMT0001 (24864323) : Row count estimate = -1.
PS1 - SQL insert affected 1 rows and returned 0 keys
PS1 - getUpdateCount()=1
as400: PreparedStatement STMT0002 (19098837)  open. Parent: Connection productionServer (367156) .
as400: PreparedStatement STMT0002 (19098837) : Escape processing = "true".
as400: PreparedStatement STMT0002 (19098837) : Fetch direction = "1000".
as400: PreparedStatement STMT0002 (19098837) : Fetch size = "0".
as400: PreparedStatement STMT0002 (19098837) : Max field size = "0".
as400: PreparedStatement STMT0002 (19098837) : Max rows = "0".
as400: PreparedStatement STMT0002 (19098837) : Query timeout = "0".
as400: PreparedStatement STMT0002 (19098837) : Result set concurrency = "1007".
as400: PreparedStatement STMT0002 (19098837) : Result set holdability = "1".
as400: PreparedStatement STMT0002 (19098837) : Result set type = "1003".
as400: PreparedStatement STMT0002 (19098837) : Behavior Override = "0".
as400: PreparedStatement STMT0002 (19098837) : Data to correlate statement with cursor Cursor CRSR0002 (12470752) .
as400: PreparedStatement STMT0002 (19098837) : Preparing [insert into test_v6r1 (id, value) values (?, ?)].
as400: PreparedStatement STMT0002 (19098837) : Prepared STMT0002*, SQL Statement -->[insert into test_v6r1 (id, value) values (?, ?)].
as400: PreparedStatement STMT0002 (19098837) : setInt().
as400: PreparedStatement STMT0002 (19098837) : parameter index: 1 value: 2.
as400: PreparedStatement STMT0002 (19098837) : setString().
as400: PreparedStatement STMT0002 (19098837) : parameter index: 2 value: Test: 2011-04-27 16:34:30.981.
as400: PreparedStatement STMT0002 (19098837) : Descriptor 2 created or changed.
as400: PreparedStatement STMT0002 (19098837) : Executed STMT0002*, SQL Statement --> [insert into test_v6r1 (id, value) values (?, ?)].
as400: PreparedStatement STMT0002 (19098837) : Update count = 1.
as400: PreparedStatement STMT0002 (19098837) : Result set = false.
as400: PreparedStatement STMT0002 (19098837) : Number of result sets = 0.
as400: PreparedStatement STMT0002 (19098837) : Row count estimate = -1.
PS2 - SQL insert affected 1 rows and returned 0 keys
PS2 - getUpdateCount()=1
as400: Connection productionServer (367156) : Testing to see if cursors should be held..
as400: Connection productionServer (367156) : Transaction commit.
as400: ResultSet  (2850225)  closed.
as400: PreparedStatement STMT0001 (24864323)  closed.
as400: PreparedStatement STMT0002 (19098837)  closed.
as400: Connection productionServer (367156)  closed.

V6R1 控制台输出:

Toolbox for Java - Open Source Software, JTOpen 7.3, codebase 5770-SS1 V7R1M0.03 2011/01/14 @B5
.
.
.
as400: Driver AS/400 Toolbox for Java JDBC Driver (27979955) : Using IBM Toolbox for Java JDBC driver implementation.
as400: Properties  (16020374) : metadata source = "0".
as400: Toolbox for Java - Open Source Software, JTOpen 7.3, codebase 5770-SS1 V7R1M0.03 2011/01/14 @B5
as400: JDBC Level: 40
as400: Properties  (16020374) : package ccsid = "13488".
as400: Connection testServer (11463270) : Client CCSID = 13488.
as400: Connection testServer (11463270) : Setting server NLV = 2912.
as400: Connection testServer (11463270) : Client functional level = V7R1M01   .
as400: Connection testServer (11463270) : Data compression = RLE.
as400: Connection testServer (11463270) : ROWID supported = true.
as400: Connection testServer (11463270) : True auto-commit supported = true.
as400: Connection testServer (11463270) : 128 byte column names supported = true.
as400: Connection testServer (11463270) : Maximum decimal precision = 31.
as400: Connection testServer (11463270) : Maximum decimal scale = 31.
as400: Connection testServer (11463270) : Minimum divide scale = 0.
as400: Connection testServer (11463270) : Translate hex = character.
as400: Connection testServer (11463270) : query optimize goal = 0.
as400: Connection testServer (11463270) : query storage limit = -1.
as400: Connection testServer (11463270) : Using extended datastreams.
as400: Connection testServer (11463270) : JDBC driver major version = 9.
as400: Connection testServer (11463270) : IBM i VRM = V6R1M0.
as400: Connection testServer (11463270) : Server CCSID = 870.
as400: Connection testServer (11463270) : Server functional level = V6R1M00014 (14).
as400: Connection testServer (11463270) : Server job identifier = 072485/QUSER/QZDASOINIT.
as400: Properties  (16020374) : decimal separator = ".".
as400: Properties  (16020374) : date format = "dmy".
as400: Properties  (16020374) : date separator = "/".
as400: Properties  (16020374) : time format = "hms".
as400: Properties  (16020374) : time separator = ":".
as400: Connection S65AB7B0 (11463270)  open.
as400: Connection S65AB7B0 (11463270) : Auto commit = "true".
as400: Connection S65AB7B0 (11463270) : Read only = "false".
as400: Connection S65AB7B0 (11463270) : Transaction isolation = "1".
as400: Connection S65AB7B0 (11463270) : Auto commit = "false".
as400: PreparedStatement STMT0001 (15696851)  open. Parent: Connection S65AB7B0 (11463270) .
as400: PreparedStatement STMT0001 (15696851) : Escape processing = "true".
as400: PreparedStatement STMT0001 (15696851) : Fetch direction = "1000".
as400: PreparedStatement STMT0001 (15696851) : Fetch size = "0".
as400: PreparedStatement STMT0001 (15696851) : Max field size = "0".
as400: PreparedStatement STMT0001 (15696851) : Max rows = "0".
as400: PreparedStatement STMT0001 (15696851) : Query timeout = "0".
as400: PreparedStatement STMT0001 (15696851) : Result set concurrency = "1007".
as400: PreparedStatement STMT0001 (15696851) : Result set holdability = "1".
as400: PreparedStatement STMT0001 (15696851) : Result set type = "1003".
as400: PreparedStatement STMT0001 (15696851) : Behavior Override = "0".
as400: PreparedStatement STMT0001 (15696851) : Data to correlate statement with cursor Cursor CRSR0001 (12039161) .
as400: PreparedStatement STMT0001 (15696851) : Preparing [SELECT *SQLGENCOLUMNS FROM NEW TABLE(insert into test_v6r1 (id, value ) values (?, ?))].
as400: PreparedStatement STMT0001 (15696851) : Prepared STMT0001*, SQL Statement -->[SELECT *SQLGENCOLUMNS FROM NEW TABLE(insert into test_v6r1 (id, value ) values (?, ?))].
as400: PreparedStatement STMT0001 (15696851) : setInt().
as400: PreparedStatement STMT0001 (15696851) : parameter index: 1 value: 1.
as400: PreparedStatement STMT0001 (15696851) : setString().
as400: PreparedStatement STMT0001 (15696851) : parameter index: 2 value: Test: 2011-04-27 16:39:53.839.
as400: PreparedStatement STMT0001 (15696851) : Descriptor 1 created or changed.
as400: Cursor CRSR0001 (12039161)  open.
as400: ResultSet CRSR0001 (13725633)  open. Parent: PreparedStatement STMT0001 (15696851) .
as400: ResultSet CRSR0001 (13725633) : Conncurrency = "1007".
as400: ResultSet CRSR0001 (13725633) : Fetch direction = "1000".
as400: ResultSet CRSR0001 (13725633) : Fetch size = "0".
as400: ResultSet CRSR0001 (13725633) : Max rows = "0".
as400: ResultSet CRSR0001 (13725633) : Type = "1004".
as400: PreparedStatement STMT0001 (15696851) : Executed STMT0001*, SQL Statement --> [SELECT *SQLGENCOLUMNS FROM NEW TABLE(insert into test_v6r1 (id, value ) values (?, ?))].
as400: PreparedStatement STMT0001 (15696851) : Update count = 0.
as400: PreparedStatement STMT0001 (15696851) : Result set = false.
as400: PreparedStatement STMT0001 (15696851) : Number of result sets = 0.
as400: PreparedStatement STMT0001 (15696851) : Row count estimate = -1.
as400: Connection S65AB7B0 (11463270) : Fetching a block of data from the system.
PS1 - SQL insert affected 0 rows and returned 0 keys
PS1 - getUpdateCount()=0
as400: PreparedStatement STMT0002 (540190)  open. Parent: Connection S65AB7B0 (11463270) .
as400: PreparedStatement STMT0002 (540190) : Escape processing = "true".
as400: PreparedStatement STMT0002 (540190) : Fetch direction = "1000".
as400: PreparedStatement STMT0002 (540190) : Fetch size = "0".
as400: PreparedStatement STMT0002 (540190) : Max field size = "0".
as400: PreparedStatement STMT0002 (540190) : Max rows = "0".
as400: PreparedStatement STMT0002 (540190) : Query timeout = "0".
as400: PreparedStatement STMT0002 (540190) : Result set concurrency = "1007".
as400: PreparedStatement STMT0002 (540190) : Result set holdability = "1".
as400: PreparedStatement STMT0002 (540190) : Result set type = "1003".
as400: PreparedStatement STMT0002 (540190) : Behavior Override = "0".
as400: PreparedStatement STMT0002 (540190) : Data to correlate statement with cursor Cursor CRSR0002 (19287723) .
as400: PreparedStatement STMT0002 (540190) : Preparing [insert into test_v6r1 (id, value) values (?, ?)].
as400: PreparedStatement STMT0002 (540190) : Prepared STMT0002*, SQL Statement -->[insert into test_v6r1 (id, value) values (?, ?)].
as400: PreparedStatement STMT0002 (540190) : setInt().
as400: PreparedStatement STMT0002 (540190) : parameter index: 1 value: 2.
as400: PreparedStatement STMT0002 (540190) : setString().
as400: PreparedStatement STMT0002 (540190) : parameter index: 2 value: Test: 2011-04-27 16:39:53.839.
as400: PreparedStatement STMT0002 (540190) : Descriptor 2 created or changed.
as400: PreparedStatement STMT0002 (540190) : Executed STMT0002*, SQL Statement --> [insert into test_v6r1 (id, value) values (?, ?)].
as400: PreparedStatement STMT0002 (540190) : Update count = 1.
as400: PreparedStatement STMT0002 (540190) : Result set = false.
as400: PreparedStatement STMT0002 (540190) : Number of result sets = 0.
as400: PreparedStatement STMT0002 (540190) : Row count estimate = -1.
PS2 - SQL insert affected 1 rows and returned 0 keys
PS2 - getUpdateCount()=1
as400: Connection S65AB7B0 (11463270) : Testing to see if cursors should be held..
as400: Connection S65AB7B0 (11463270) : Transaction commit.
as400: Cursor CRSR0001 (12039161) : Closing with reuse flag = 240.
as400: Cursor CRSR0001 (12039161)  closed.
as400: ResultSet CRSR0001 (13725633)  closed.
as400: PreparedStatement STMT0001 (15696851)  closed.
as400: PreparedStatement STMT0002 (540190)  closed.
as400: Connection S65AB7B0 (11463270)  closed.

当使用标志 RETURN_GENERATED_KEYS 时应该注意的最重要的事情是准备语句的准备方式。

在 V6R1 的情况下,这样的声明:

insert into test_v6r1 (id, value ) values (?, ?)

内部准备为:

SELECT *SQLGENCOLUMNS FROM NEW TABLE(insert into test_v6r1 (id, value ) values (?, ?))

在 V5R4 的情况下,它是正常准备的:

insert into test_v6r1 (id, value ) values (?, ?)

PreparedStatement.executeUpdate() 的 Javadoc说:

Executes the SQL statement in this PreparedStatement object, which must be an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.

Returns: either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing

而且执行的语句明显是DML语句。 我怀疑这是 JTOpen/JT400 中的错误。 我试过 6.1 和 7.3,结果是一样的。

关于java - 通过JBDC获取在IBM DB2 V6R1 (AS400)上插入的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5803036/

有关java - 通过JBDC获取在IBM DB2 V6R1 (AS400)上插入的行数的更多相关文章

  1. ruby-on-rails - 结合 meta_search 与 acts_as_taggable_on - 2

    我在开发的Rails3网站的一些搜索功能上遇到了一个小问题。我有一个简单的Post模型,如下所示:classPost我正在使用acts_as_taggable_on来更轻松地向我的帖子添加标签。当我有一个标记为“rails”的帖子并执行以下操作时,一切正常:@posts=Post.tagged_with("rails")问题是,我还想搜索帖子的标题。当我有一篇标题为“Helloworld”并标记为“rails”的帖子时,我希望能够通过搜索“hello”或“rails”来找到这篇帖子。因此,我希望标题列的LIKE语句与acts_as_taggable_on提供的tagged_with方法

  2. java - 等价于 Java 中的 Ruby Hash - 2

    我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/

  3. java - 从 JRuby 调用 Java 类的问题 - 2

    我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www

  4. java - 我的模型类或其他类中应该有逻辑吗 - 2

    我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我

  5. java - 什么相当于 ruby​​ 的 rack 或 python 的 Java wsgi? - 2

    什么是ruby​​的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht

  6. Observability:从零开始创建 Java 微服务并监控它 (二) - 2

    这篇文章是继上一篇文章“Observability:从零开始创建Java微服务并监控它(一)”的续篇。在上一篇文章中,我们讲述了如何创建一个Javaweb应用,并使用Filebeat来收集应用所生成的日志。在今天的文章中,我来详述如何收集应用的指标,使用APM来监控应用并监督web服务的在线情况。源码可以在地址 https://github.com/liu-xiao-guo/java_observability 进行下载。摄入指标指标被视为可以随时更改的时间点值。当前请求的数量可以改变任何毫秒。你可能有1000个请求的峰值,然后一切都回到一个请求。这也意味着这些指标可能不准确,你还想提取最小/

  7. 【Java 面试合集】HashMap中为什么引入红黑树,而不是AVL树呢 - 2

    HashMap中为什么引入红黑树,而不是AVL树呢1.概述开始学习这个知识点之前我们需要知道,在JDK1.8以及之前,针对HashMap有什么不同。JDK1.7的时候,HashMap的底层实现是数组+链表JDK1.8的时候,HashMap的底层实现是数组+链表+红黑树我们要思考一个问题,为什么要从链表转为红黑树呢。首先先让我们了解下链表有什么不好???2.链表上述的截图其实就是链表的结构,我们来看下链表的增删改查的时间复杂度增:因为链表不是线性结构,所以每次添加的时候,只需要移动一个节点,所以可以理解为复杂度是N(1)删:算法时间复杂度跟增保持一致查:既然是非线性结构,所以查询某一个节点的时候

  8. 【Java入门】使用Java实现文件夹的遍历 - 2

    遍历文件夹我们通常是使用递归进行操作,这种方式比较简单,也比较容易理解。本文为大家介绍另一种不使用递归的方式,由于没有使用递归,只用到了循环和集合,所以效率更高一些!一、使用递归遍历文件夹整体思路1、使用File封装初始目录,2、打印这个目录3、获取这个目录下所有的子文件和子目录的数组。4、遍历这个数组,取出每个File对象4-1、如果File是否是一个文件,打印4-2、否则就是一个目录,递归调用代码实现publicclassSearchFile{publicstaticvoidmain(String[]args){//初始目录Filedir=newFile("d:/Dev");Datebeg

  9. java - 为什么 ruby​​ modulo 与 java/other lang 不同? - 2

    我基本上来自Java背景并且努力理解Ruby中的模运算。(5%3)(-5%3)(5%-3)(-5%-3)Java中的上述操作产生,2个-22个-2但在Ruby中,相同的表达式会产生21个-1-2.Ruby在逻辑上有多擅长这个?模块操作在Ruby中是如何实现的?如果将同一个操作定义为一个web服务,两个服务如何匹配逻辑。 最佳答案 在Java中,模运算的结果与被除数的符号相同。在Ruby中,它与除数的符号相同。remainder()在Ruby中与被除数的符号相同。您可能还想引用modulooperation.

  10. java - Ruby 相当于 Java 的 Collections.unmodifiableList 和 Collections.unmodifiableMap - 2

    Java的Collections.unmodifiableList和Collections.unmodifiableMap在Ruby标准API中是否有等价物? 最佳答案 使用freeze应用程序接口(interface):Preventsfurthermodificationstoobj.ARuntimeErrorwillberaisedifmodificationisattempted.Thereisnowaytounfreezeafrozenobject.SeealsoObject#frozen?.Thismethodretur

随机推荐