當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。