当前位置: 首页>>代码示例>>Java>>正文


Java CallableStatement.getGeneratedKeys方法代码示例

本文整理汇总了Java中java.sql.CallableStatement.getGeneratedKeys方法的典型用法代码示例。如果您正苦于以下问题:Java CallableStatement.getGeneratedKeys方法的具体用法?Java CallableStatement.getGeneratedKeys怎么用?Java CallableStatement.getGeneratedKeys使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.CallableStatement的用法示例。


在下文中一共展示了CallableStatement.getGeneratedKeys方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCallStmtExecuteLargeUpdate

import java.sql.CallableStatement; //导入方法依赖的package包/类
/**
 * Test for CallableStatement.executeLargeUpdate().
 * Validate update count returned and generated keys.
 */
public void testCallStmtExecuteLargeUpdate() throws Exception {
    createTable("testExecuteLargeUpdate", "(id BIGINT AUTO_INCREMENT PRIMARY KEY, n INT)");
    createProcedure("testExecuteLargeUpdateProc", "(IN n1 INT, IN n2 INT, IN n3 INT, IN n4 INT, IN n5 INT) BEGIN "
            + "INSERT INTO testExecuteLargeUpdate (n) VALUES (n1), (n2), (n3), (n4), (n5); END");

    CallableStatement testCstmt = this.conn.prepareCall("{CALL testExecuteLargeUpdateProc(?, ?, ?, ?, ?)}");
    testCstmt.setInt(1, 1);
    testCstmt.setInt(2, 2);
    testCstmt.setInt(3, 3);
    testCstmt.setInt(4, 4);
    testCstmt.setInt(5, 5);

    long count = testCstmt.executeLargeUpdate();
    assertEquals(5, count);
    assertEquals(5, testCstmt.getLargeUpdateCount());

    this.rs = testCstmt.getGeneratedKeys();

    // Although not requested, CallableStatements makes gerenated keys always available.
    ResultSetMetaData rsmd = this.rs.getMetaData();
    assertEquals(1, rsmd.getColumnCount());
    assertEquals(JDBCType.BIGINT.getVendorTypeNumber().intValue(), rsmd.getColumnType(1));
    assertEquals(20, rsmd.getColumnDisplaySize(1));

    // We can't check the generated keys as they are not returned correctly in this case (last_insert_id is missing from OK_PACKET when executing inserts
    // within a stored procedure - Bug#21792359).
    //        long generatedKey = 0;
    //        while (this.rs.next()) {
    //            assertEquals(++generatedKey, this.rs.getLong(1));
    //        }
    //        assertEquals(5, generatedKey);
    this.rs.close();
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:38,代码来源:StatementsTest.java


注:本文中的java.sql.CallableStatement.getGeneratedKeys方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。