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


Java Connection.commit方法代码示例

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


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

示例1: updateNodeHeartbeat

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Method to update the node heartbeat value to the current time.
 *
 * @param nodeId local node ID
 * @return true if the update is successful, false otherwise
 * @throws CoordinationException if an error is detected while updating the node heartbeat.
 */
public boolean updateNodeHeartbeat(String nodeId) throws CoordinationException {
    Connection connection = null;
    PreparedStatement preparedStatementForNodeUpdate = null;
    String task = RdbmsCoordinationConstants.TASK_UPDATE_NODE_HEARTBEAT;
    try {
        connection = getConnection();
        preparedStatementForNodeUpdate = connection.prepareStatement(
                RdbmsCoordinationConstants.PS_UPDATE_NODE_HEARTBEAT);
        preparedStatementForNodeUpdate.setLong(1, System.currentTimeMillis());
        preparedStatementForNodeUpdate.setString(2, nodeId);
        int updateCount = preparedStatementForNodeUpdate.executeUpdate();
        connection.commit();
        return updateCount != 0;
    } catch (SQLException e) {
        rollback(connection, task);
        throw new CoordinationException("Error occurred while " + task + ". Node ID: " + nodeId, e);
    } finally {
        close(preparedStatementForNodeUpdate, task);
        close(connection, task);
    }
}
 
开发者ID:wso2,项目名称:message-broker,代码行数:29,代码来源:RdbmsCoordinationDaoImpl.java

示例2: testLifecyleInterceptor

import java.sql.Connection; //导入方法依赖的package包/类
public void testLifecyleInterceptor() throws Exception {
    createTable("testLifecycleInterceptor", "(field1 int)", "InnoDB");
    Connection liConn = null;

    try {
        liConn = getConnectionWithProps("connectionLifecycleInterceptors=testsuite.simple.TestLifecycleInterceptor");
        liConn.setAutoCommit(false);

        liConn.createStatement().executeUpdate("INSERT INTO testLifecycleInterceptor VALUES (1)");
        liConn.commit();
        assertEquals(TestLifecycleInterceptor.transactionsBegun, 1);
        assertEquals(TestLifecycleInterceptor.transactionsCompleted, 1);
        liConn.createStatement().execute("SELECT * FROM testLifecycleInterceptor");
        assertEquals(TestLifecycleInterceptor.transactionsBegun, 2);
        // implicit commit
        liConn.createStatement().executeUpdate("CREATE TABLE testLifecycleFoo (field1 int)");
        assertEquals(TestLifecycleInterceptor.transactionsCompleted, 2);
    } finally {
        if (liConn != null) {
            liConn.createStatement().executeUpdate("DROP TABLE IF EXISTS testLifecycleFoo");
            liConn.close();
        }
    }

}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:26,代码来源:ConnectionTest.java

示例3: persist

import java.sql.Connection; //导入方法依赖的package包/类
@Override
public void persist(Queue queue) throws BrokerException {
    Connection connection = null;
    PreparedStatement statement = null;
    try {
        connection = getConnection();
        statement = connection.prepareStatement(RDBMSConstants.PS_INSERT_QUEUE);
        statement.setString(1, queue.getName());
        statement.setBytes(2, new byte[0]);
        statement.executeUpdate();

        connection.commit();
    } catch (SQLException e) {
        throw new BrokerException("Error occurred while storing queue " + queue, e);
    } finally {
        close(connection, statement);
    }
}
 
开发者ID:wso2,项目名称:message-broker,代码行数:19,代码来源:QueueDaoImpl.java

示例4: testFindWithClassificationMapperDomainAndCategory

import java.sql.Connection; //导入方法依赖的package包/类
@Test
public void testFindWithClassificationMapperDomainAndCategory()
    throws NotAuthorizedException, SQLException, ClassificationAlreadyExistException,
    ClassificationNotFoundException {
    Connection connection = dataSource.getConnection();
    taskanaEngineImpl.setConnection(connection);
    Classification classification1 = this.createNewClassificationWithUniqueKey("domain1", "t1");
    classification1.setCategory("category1");
    classificationService.createClassification(classification1);
    Classification classification2 = this.createNewClassificationWithUniqueKey("domain2", "t1");
    classification2.setCategory("category1");
    classificationService.createClassification(classification2);

    Classification classification3 = this.createNewClassificationWithUniqueKey("domain1", "t1");
    classification3.setCategory("category2");
    classificationService.createClassification(classification3);

    List<ClassificationSummary> list = classificationService.createClassificationQuery()
        .category("category1")
        .domain("domain1")
        .list();
    Assert.assertEquals(1, list.size());
    list = classificationService.createClassificationQuery().domain("domain1", "domain3").list();
    Assert.assertEquals(2, list.size());
    connection.commit();
}
 
开发者ID:Taskana,项目名称:taskana,代码行数:27,代码来源:ClassificationServiceImplIntExplicitTest.java

示例5: getConnection

import java.sql.Connection; //导入方法依赖的package包/类
@Override
protected Connection getConnection() {
  try {
    Connection conn = dbConf.getConnection();
    conn.setAutoCommit(false);
    PreparedStatement stmt =
        conn.prepareStatement("SET extra_float_digits TO 0");
    stmt.executeUpdate();
    conn.commit();
    return conn;
  } catch (SQLException sqlE) {
    LOG.error("Could not get connection to test server: " + sqlE);
    return null;
  } catch (ClassNotFoundException cnfE) {
    LOG.error("Could not find driver class: " + cnfE);
    return null;
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:19,代码来源:DirectPostgreSQLExportManualTest.java

示例6: loadDatabase

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Invoke this benchmark's database loader using the given Connection handle
 * @param conn
 */
protected final void loadDatabase(Connection conn, boolean calibrate, boolean generateFiles, String filesPath) {
    try {
        Loader loader = this.makeLoaderImpl(conn, calibrate,generateFiles,filesPath);
        if (loader != null) {
            conn.setAutoCommit(false);
            loader.load();
            conn.commit();

            if (loader.getTableCounts().isEmpty() == false) {
                LOG.info("Table Counts:\n" + loader.getTableCounts());
            }
        }
    } catch (SQLException ex) {
        throw new RuntimeException(String.format("Unexpected error when trying to load the %s database", this.benchmarkName), ex);
    }
}
 
开发者ID:faclc4,项目名称:HTAPBench,代码行数:21,代码来源:BenchmarkModule.java

示例7: testSequnce

import java.sql.Connection; //导入方法依赖的package包/类
private static void testSequnce(Connection theCon) throws SQLException {
	try {
		theCon.setAutoCommit(false);
		String sql = "select next value for MYCATSEQ_GLOBAL ";
		Statement stmt = theCon.createStatement();
		ResultSet rs = stmt.executeQuery(sql);
		if (rs.next()) {
			System.out.println(Thread.currentThread().getName()
					+ " get seq " + rs.getLong(1));
		} else {
			System.out.println(Thread.currentThread().getName()
					+ " can't get  seq ");
		}

		theCon.commit();
		stmt.close();
	} finally {
		theCon.close();
	}
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:21,代码来源:MultiThreadSequnceTest.java

示例8: insertFunction

import java.sql.Connection; //导入方法依赖的package包/类
private static void insertFunction(int id, String msg,
    SetExtraArgs setExtraArgs) throws SQLException {
  instanceForProcedure.functionCalls += 1;
  Connection con = instanceForProcedure.getConnection();

  StringBuilder sql = new StringBuilder("insert into ");
  sql.append(instanceForProcedure.getTableName());
  sql.append("(id, msg");
  for (int i = 0; i < instanceForProcedure.names.length; ++i) {
    sql.append(", ");
    sql.append(instanceForProcedure.names[i]);
  }
  sql.append(") values (");
  for (int i = 0; i < instanceForProcedure.names.length + 2; ++i) {
    sql.append("?,");
  }
  // Remove last ,
  sql = sql.delete(sql.length() - 1, sql.length());
  sql.append(")");

  PreparedStatement statement = con.prepareStatement(sql.toString());
  try {
    statement.setInt(1, id);
    statement.setString(2, msg);
    setExtraArgs.set(statement);
    statement.execute();
    con.commit();
  } finally {
    statement.close();
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:32,代码来源:TestExportUsingProcedure.java

示例9: testBug31053

import java.sql.Connection; //导入方法依赖的package包/类
public void testBug31053() throws Exception {
    Properties props = new Properties();
    props.setProperty("connectTimeout", "2000");
    props.setProperty("loadBalanceStrategy", "random");

    Connection lbConn = getLoadBalancedConnection(2, "localhost:23", props);

    lbConn.setAutoCommit(false);

    for (int i = 0; i < 10; i++) {
        lbConn.commit();
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:14,代码来源:ConnectionRegressionTest.java

示例10: doSomeWork

import java.sql.Connection; //导入方法依赖的package包/类
private static void doSomeWork() throws SQLException {

        Connection conn = getConnection();
        Statement  stmt = conn.createStatement();

        conn.setAutoCommit(false);
        stmt.execute("INSERT INTO trig_test VALUES (1, 'hello')");
        stmt.execute("INSERT INTO trig_test VALUES (2, 'now what?')");
        stmt.execute("INSERT INTO trig_test VALUES (3, 'unchangable')");
        stmt.execute("INSERT INTO trig_test VALUES (4, 'goodbye')");
        conn.commit();
        dumpTable("trig_test");
        stmt.execute("UPDATE trig_test SET value = 'all done'");
        conn.commit();
        dumpTable("trig_test");
        stmt.execute("DELETE FROM trig_test");
        conn.rollback();
        dumpTable("trig_test");

        try {
            stmt.execute("INSERT INTO trig_test VALUES(11, 'whatever')");
        } catch (SQLException se) {
            se.printStackTrace();
        }

        stmt.execute("INSERT INTO trig_test VALUES(10, 'whatever')");
        conn.commit();
        dumpTable("trig_test");
        stmt.close();
        conn.close();
    }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:32,代码来源:TriggerSample.java

示例11: dropTableIfExists

import java.sql.Connection; //导入方法依赖的package包/类
@Override
protected void dropTableIfExists(String table) throws SQLException {
  Connection conn = getManager().getConnection();
  PreparedStatement statement = conn.prepareStatement(
      "DROP TABLE IF EXISTS "
      + table, ResultSet.TYPE_FORWARD_ONLY,
      ResultSet.CONCUR_READ_ONLY);
  try {
    statement.executeUpdate();
    conn.commit();
  } finally {
    statement.close();
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:15,代码来源:CubridCompatTest.java

示例12: dropTableIfExists

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Drop a table if it already exists in the database.
 *
 * @param table
 *            the name of the table to drop.
 * @throws SQLException
 *             if something goes wrong.
 */
protected void dropTableIfExists(String table) throws SQLException {
  Connection conn = getManager().getConnection();
  String sqlStmt = "IF OBJECT_ID('" + table
      + "') IS NOT NULL  DROP TABLE " + table;

  PreparedStatement statement = conn.prepareStatement(sqlStmt,
      ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
  try {
    statement.executeUpdate();
    conn.commit();
  } finally {
    statement.close();
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:23,代码来源:SQLServerParseMethodsManualTest.java

示例13: testFindWithClassificationMapperCustomAndCategory

import java.sql.Connection; //导入方法依赖的package包/类
@Test
public void testFindWithClassificationMapperCustomAndCategory()
    throws NotAuthorizedException, SQLException, ClassificationAlreadyExistException,
    ClassificationNotFoundException {
    Connection connection = dataSource.getConnection();
    taskanaEngineImpl.setConnection(connection);
    Classification classification1 = this.createNewClassificationWithUniqueKey("", "t1");
    classification1.setDescription("DESC1");
    classification1.setCategory("category1");
    classificationService.createClassification(classification1);
    Classification classification2 = this.createNewClassificationWithUniqueKey("", "t1");
    classification2.setDescription("DESC1");
    classification2.setCustom1("custom1");
    classification2.setCategory("category1");
    classificationService.createClassification(classification2);
    Classification classification3 = this.createNewClassificationWithUniqueKey("", "t1");
    classification3.setCustom1("custom2");
    classification3.setCustom2("custom1");
    classification3.setCategory("category2");
    classificationService.createClassification(classification3);
    Classification classification4 = this.createNewClassificationWithUniqueKey("", "t1");
    classification4.setDescription("description2");
    classification4.setCustom8("custom2");
    classification4.setCategory("category1");
    classificationService.createClassification(classification4);

    List<ClassificationSummary> list = classificationService.createClassificationQuery()
        .descriptionLike("DESC1")
        .customFields("custom1")
        .list();
    Assert.assertEquals(1, list.size());
    list = classificationService.createClassificationQuery().customFields("custom2").list();
    Assert.assertEquals(2, list.size());
    list = classificationService.createClassificationQuery().descriptionLike("DESC1").category("category1").list();
    Assert.assertEquals(2, list.size());
    connection.commit();
}
 
开发者ID:Taskana,项目名称:taskana,代码行数:38,代码来源:ClassificationServiceImplIntExplicitTest.java

示例14: close

import java.sql.Connection; //导入方法依赖的package包/类
public static void close(Connection connection) {
	try {
		if (connection != null) {
			if (!connection.getAutoCommit())
				connection.commit();
			connection.close();
		}
	}
	catch (SQLException e) {
		e.printStackTrace();
	}
}
 
开发者ID:HPI-Information-Systems,项目名称:metanome-algorithms,代码行数:13,代码来源:DatabaseUtils.java

示例15: testBug56429

import java.sql.Connection; //导入方法依赖的package包/类
public void testBug56429() throws Exception {
    Properties props = new Driver().parseURL(BaseTestCase.dbUrl, null);
    props.setProperty("autoReconnect", "true");
    props.setProperty("socketFactory", "testsuite.UnreliableSocketFactory");

    Properties urlProps = new NonRegisteringDriver().parseURL(BaseTestCase.dbUrl, null);

    String host = urlProps.getProperty(NonRegisteringDriver.HOST_PROPERTY_KEY);
    String port = urlProps.getProperty(NonRegisteringDriver.PORT_PROPERTY_KEY);

    props.remove(NonRegisteringDriver.HOST_PROPERTY_KEY);
    props.remove(NonRegisteringDriver.NUM_HOSTS_PROPERTY_KEY);
    props.remove(NonRegisteringDriver.HOST_PROPERTY_KEY + ".1");
    props.remove(NonRegisteringDriver.PORT_PROPERTY_KEY + ".1");

    props.setProperty("queriesBeforeRetryMaster", "50");
    props.setProperty("maxReconnects", "1");

    UnreliableSocketFactory.mapHost("master", host);
    UnreliableSocketFactory.mapHost("slave", host);

    Connection failoverConnection = null;

    try {
        failoverConnection = getConnectionWithProps("jdbc:mysql://master:" + port + ",slave:" + port + "/", props);

        String userHost = getSingleIndexedValueWithQuery(1, "SELECT USER()").toString();
        String[] userParts = userHost.split("@");

        this.rs = this.stmt.executeQuery("SHOW PROCESSLIST");

        int startConnCount = 0;

        while (this.rs.next()) {
            if (this.rs.getString("User").equals(userParts[0]) && this.rs.getString("Host").equals(userParts[1])) {
                startConnCount++;
            }
        }

        assert (startConnCount > 0);

        failoverConnection.setAutoCommit(false); // this will fail if state
                                                // not copied over

        for (int i = 0; i < 20; i++) {

            failoverConnection.commit();
        }

        this.rs = this.stmt.executeQuery("SHOW PROCESSLIST");

        int endConnCount = 0;

        while (this.rs.next()) {
            if (this.rs.getString("User").equals(userParts[0]) && this.rs.getString("Host").equals(userParts[1])) {
                endConnCount++;
            }
        }

        assert (endConnCount > 0);

        if (endConnCount - startConnCount >= 20) { // this may be bogus if run on a real system, we should probably look to see they're coming from this
                                                      // testsuite?
            fail("We're leaking connections even when not failed over");
        }
    } finally {
        if (failoverConnection != null) {
            failoverConnection.close();
        }
    }
}
 
开发者ID:Jugendhackt,项目名称:OpenVertretung,代码行数:72,代码来源:ConnectionRegressionTest.java


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