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


Java DatabaseMetaData.supportsSavepoints方法代码示例

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


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

示例1: testSavepoint

import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
/**
 * Tests the savepoint functionality in MySQL.
 * 
 * @throws Exception
 *             if an error occurs.
 */
public void testSavepoint() throws Exception {
    DatabaseMetaData dbmd = this.conn.getMetaData();

    if (dbmd.supportsSavepoints()) {
        System.out.println("Testing SAVEPOINTs");

        try {
            this.conn.setAutoCommit(true);

            createTable("testSavepoints", "(field1 int)", "InnoDB");

            // Try with named save points
            this.conn.setAutoCommit(false);
            this.stmt.executeUpdate("INSERT INTO testSavepoints VALUES (1)");

            Savepoint afterInsert = this.conn.setSavepoint("afterInsert");
            this.stmt.executeUpdate("UPDATE testSavepoints SET field1=2");

            Savepoint afterUpdate = this.conn.setSavepoint("afterUpdate");
            this.stmt.executeUpdate("DELETE FROM testSavepoints");

            assertTrue("Row count should be 0", getRowCount("testSavepoints") == 0);
            this.conn.rollback(afterUpdate);
            assertTrue("Row count should be 1", getRowCount("testSavepoints") == 1);
            assertTrue("Value should be 2", "2".equals(getSingleValue("testSavepoints", "field1", null).toString()));
            this.conn.rollback(afterInsert);
            assertTrue("Value should be 1", "1".equals(getSingleValue("testSavepoints", "field1", null).toString()));
            this.conn.rollback();
            assertTrue("Row count should be 0", getRowCount("testSavepoints") == 0);

            // Try with 'anonymous' save points
            this.conn.rollback();

            this.stmt.executeUpdate("INSERT INTO testSavepoints VALUES (1)");
            afterInsert = this.conn.setSavepoint();
            this.stmt.executeUpdate("UPDATE testSavepoints SET field1=2");
            afterUpdate = this.conn.setSavepoint();
            this.stmt.executeUpdate("DELETE FROM testSavepoints");

            assertTrue("Row count should be 0", getRowCount("testSavepoints") == 0);
            this.conn.rollback(afterUpdate);
            assertTrue("Row count should be 1", getRowCount("testSavepoints") == 1);
            assertTrue("Value should be 2", "2".equals(getSingleValue("testSavepoints", "field1", null).toString()));
            this.conn.rollback(afterInsert);
            assertTrue("Value should be 1", "1".equals(getSingleValue("testSavepoints", "field1", null).toString()));
            this.conn.rollback();

            this.conn.releaseSavepoint(this.conn.setSavepoint());
        } finally {
            this.conn.setAutoCommit(true);
        }
    } else {
        System.out.println("MySQL version does not support SAVEPOINTs");
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:62,代码来源:ConnectionTest.java


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