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


Java Connection.getAutoCommit方法代码示例

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


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

示例1: runCommands

import java.sql.Connection; //导入方法依赖的package包/类
public static void runCommands(Connection connection, List<String> commands) {
    try {
        boolean originalAutoCommit = connection.getAutoCommit();
        try {
            if (!originalAutoCommit) {
                connection.setAutoCommit(true);
            }

            for (String command : commands) {
                execCommand(connection, command);
            }
        } finally {
            connection.setAutoCommit(originalAutoCommit);
        }
    } catch (Exception e) {
        throw new RuntimeException("Error running script.  Cause: " + e, e);
    }
}
 
开发者ID:EMResearch,项目名称:EvoMaster,代码行数:19,代码来源:SqlScriptRunner.java

示例2: upgrade

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Perform upgrade.
 */
public void upgrade(final Connection conn, final int upgradeToVersion) throws SQLException {
  final boolean savedAutoCommit = conn.getAutoCommit();
  Statement st = null; // NOPMD
  PreparedStatement pstmt = null; // NOPMD
  try {
    // create statement
    conn.setAutoCommit(true);
    st = conn.createStatement();

    log.debug("Updating version");
    st.executeUpdate("update SYSTEM_PROPERTY set VALUE = '" + upgraderVersion() + "' where NAME = 'parabuild.schema.version' ");

    // finish
    conn.commit();

    // request post-startup config manager action
    System.setProperty(SystemConstants.SYSTEM_PROPERTY_INIT_ADVANCED_SETTINGS, "true");
  } finally {
    IoUtils.closeHard(pstmt);
    IoUtils.closeHard(st);
    conn.setAutoCommit(savedAutoCommit);
  }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:27,代码来源:UpgraderToVersion17.java

示例3: loadSqlTable

import java.sql.Connection; //导入方法依赖的package包/类
private void loadSqlTable(Connection conn, String table, int count,
  ColumnGenerator... extraCols) throws Exception {
  PreparedStatement statement = conn.prepareStatement(
    getSqlInsertTableStatement(table, extraCols),
    ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
  try {
    for (int i = 0; i < count; ++i) {
      statement.setObject(1, i, Types.INTEGER);
      statement.setObject(2, "textfield" + i, Types.VARCHAR);
      for (int j = 0; j < extraCols.length; ++j) {
        statement.setObject(j + 3, extraCols[j].getDBValue(i),
          extraCols[j].getSqlType());
      }
      statement.executeUpdate();
    }
    if (!conn.getAutoCommit()) {
      conn.commit();
    }
  } finally {
    statement.close();
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:23,代码来源:HCatalogTestUtils.java

示例4: close

import java.sql.Connection; //导入方法依赖的package包/类
@Override
public void close() throws IOException
{
    try
    {
        Connection connection = sqlSession.getConnection();
        if (!connection.getAutoCommit())
        {
            connection.setAutoCommit(true);
        }
    } catch (SQLException e)
    {
        throw new IOException(e);
    }
    sqlSession.close();
}
 
开发者ID:gzxishan,项目名称:OftenPorter,代码行数:17,代码来源:DBHandleOnlyTS.java

示例5: getConnection

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @param datasourceName 取得するコネクションのデータソース名
 *
 * @see jp.co.future.uroborosql.connection.ConnectionSupplier#getConnection(java.lang.String)
 */
@Override
public Connection getConnection(final String datasourceName) {
	try {
		DataSource ds = dsMap.computeIfAbsent(datasourceName, DataSourceConnectionSupplierImpl::getNewDataSource);
		final Connection connection;
		synchronized (ds) {
			connection = ds.getConnection();
		}
		boolean autoCommit = getAutoCommit(datasourceName);
		if (connection.getAutoCommit() != autoCommit) {
			connection.setAutoCommit(autoCommit);
		}
		boolean readOnly = getReadOnly(datasourceName);
		if (connection.isReadOnly() != readOnly) {
			connection.setReadOnly(readOnly);
		}
		int transactionIsolation = getTransactionIsolation(datasourceName);
		if (transactionIsolation > 0 && connection.getTransactionIsolation() != transactionIsolation) {
			connection.setTransactionIsolation(transactionIsolation);
		}
		return connection;
	} catch (SQLException ex) {
		throw new UroborosqlRuntimeException("Connection[" + datasourceName + "] can not be acquired.", ex);
	}
}
 
开发者ID:future-architect,项目名称:uroborosql,代码行数:33,代码来源:DataSourceConnectionSupplierImpl.java

示例6: rollback

import java.sql.Connection; //导入方法依赖的package包/类
public void rollback() throws SQLException {
    MC mc = getManagedConnection();
    if (mc.isInXaTransaction()) {
        throw new SQLException("Can not rollback within an XA transaction");
    }
    Connection c = mc.getPhysicalConnection();
    if (c.getAutoCommit()) {
        return;
    }

    try {
        LocalTransaction tx = mc.getClientLocalTransaction();
        tx.rollback();
        tx.begin();
    } catch (ResourceException e) {
        if (e.getCause() instanceof SQLException) {
            throw (SQLException) e.getCause();
        } else {
            throw new SQLException(e);
        }
    }
}
 
开发者ID:ops4j,项目名称:org.ops4j.pax.transx,代码行数:23,代码来源:ConnectionHandle.java

示例7: run

import java.sql.Connection; //导入方法依赖的package包/类
@Override
public void run() {
    Connection con = null;
    try {

        List<String> batch = getNextBatch();
        while (!batch.isEmpty()) {
            try {
                if (con == null || con.isClosed()) {
                    con = conPool.getConnection();
                    if (con.getAutoCommit() != autocommit) {
                        con.setAutoCommit(autocommit);
                    }
                }

                insert(con, batch);
                finshiedCount.addAndGet(batch.size());
            } catch (Exception e) {
                System.out.println("caught err in  thread :"
                        + Thread.currentThread().getId() + " " + e);
                try {
                    con.rollback();
                } catch (SQLException e1) {
                    System.out.println("caught err in thread :"
                            + Thread.currentThread().getId()
                            + " rollback err " + e1);
                }
                failedCount.addAndGet(batch.size());
            }
            batch = getNextBatch();
        }
    } finally {
        if (con != null) {
            this.conPool.returnCon(con);
        }
    }

}
 
开发者ID:actiontech,项目名称:dble,代码行数:39,代码来源:UserTableInsertJob.java

示例8: getConnection

import java.sql.Connection; //导入方法依赖的package包/类
public Connection getConnection() throws SQLException {
	
	if ( log.isTraceEnabled() ) log.trace( "total checked-out connections: " + checkedOut );
	
	synchronized (pool) {
		if ( !pool.isEmpty() ) {
			int last = pool.size() - 1;
			if ( log.isTraceEnabled() ) {
				log.trace("using pooled JDBC connection, pool size: " + last);
				checkedOut++;
			}
			Connection pooled = (Connection) pool.remove(last);
			if (isolation!=null) pooled.setTransactionIsolation( isolation.intValue() );
			if ( pooled.getAutoCommit() ) pooled.setAutoCommit(false);
			return pooled;
		}
	}
	
	log.debug("opening new JDBC connection");
	Connection conn = DriverManager.getConnection(url, connectionProps);
	if (isolation!=null) conn.setTransactionIsolation( isolation.intValue() );
	if ( conn.getAutoCommit() ) conn.setAutoCommit(false);

	if ( log.isDebugEnabled() ) {
		log.debug( "created connection to: " + url + ", Isolation Level: " + conn.getTransactionIsolation() );
	}
	if ( log.isTraceEnabled() ) checkedOut++;
	
	return conn;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:31,代码来源:DriverManagerConnectionProvider.java

示例9: upgrade

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Perform upgrade.
 */
public void upgrade(final Connection connection, final int upgradeToVersion) throws SQLException {
  final boolean savedAutoCommit = connection.getAutoCommit();
  final Statement st = connection.createStatement();
  try {
    // create statement
    connection.setAutoCommit(true);

    LOG.debug("Altering table");
    PersistanceUtils.executeDDLs(st, new String[]{

            " alter table USERS add column DISABLE_ALL_EMAIL char(1) default 'N' not null ",
            " update USERS set DISABLE_ALL_EMAIL='N' ",
            " alter table USERS alter column DISABLE_ALL_EMAIL drop default ",
    });

    LOG.debug("Updating version");
    st.executeUpdate("update SYSTEM_PROPERTY set VALUE = '" + upgraderVersion() + "' where NAME = 'parabuild.schema.version' ");

    // finish
    connection.commit();

  } finally {
    IoUtils.closeHard(st);
    connection.setAutoCommit(savedAutoCommit);
  }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:30,代码来源:UpgraderToVersion76.java

示例10: upgrade

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Perform upgrade.
 */
public void upgrade(final Connection conn, final int upgradeToVersion) throws SQLException {
  final boolean savedAutoCommit = conn.getAutoCommit();
  Statement st = null; // NOPMD
  try {
    // create statement
    conn.setAutoCommit(true);
    st = conn.createStatement();

    log.debug("Altering table");
    PersistanceUtils.executeDDLs(st, new String[]{

            " alter table MANUAL_RUN_PARAMETER add column MODIFIABLE char(1) default 'Y' not null ",
            " update MANUAL_RUN_PARAMETER set MODIFIABLE='Y' ",
            " alter table MANUAL_RUN_PARAMETER alter column MODIFIABLE drop default ",

            " alter table MANUAL_RUN_PARAMETER drop constraint MANUAL_RUN_PARAMETER_ATTRIBUTE_UC2 ",
            " alter table MANUAL_RUN_PARAMETER drop constraint MANUAL_RUN_PARAMETER_ATTRIBUTE_FC1 ",
            " drop index MANUAL_RUN_PARAMETER_IX1 ",
            " alter table MANUAL_RUN_PARAMETER add constraint MANUAL_RUN_PARAMETER_ATTRIBUTE_UC2 unique (TYPE, BUILD_ID, NAME) ",
    });

    log.debug("Updating version");
    st.executeUpdate("update SYSTEM_PROPERTY set VALUE = '" + upgraderVersion() + "' where NAME = 'parabuild.schema.version' ");

    // finish
    conn.commit();

  } finally {
    IoUtils.closeHard(st);
    conn.setAutoCommit(savedAutoCommit);
  }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:36,代码来源:UpgraderToVersion71.java

示例11: getConnection

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Grab a connection
 * @return a JDBC connection
 * @throws SQLException
 */
public Connection getConnection() throws SQLException {
    // get a connection from the pool (thru DriverManager, cfr. Proxool doc)
	Connection c = DriverManager.getConnection(proxoolAlias);
	
	// set the Transaction Isolation if defined
	if (isolation!=null) c.setTransactionIsolation( isolation.intValue() );
	
	// toggle autoCommit to false if set
	if ( c.getAutoCommit() ) c.setAutoCommit(false);
	
	// return the connection
	return c;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:19,代码来源:ProxoolConnectionProvider.java

示例12: upgrade

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Perform upgrade.
 */
public void upgrade(final Connection conn, final int upgradeToVersion) throws SQLException {
  final boolean savedAutoCommit = conn.getAutoCommit();
  Statement st = null; // NOPMD
  try {
    // create statement
    conn.setAutoCommit(true);
    st = conn.createStatement();

    log.debug("Altering table");
    PersistanceUtils.executeDDLs(st, new String[]{

            " alter table AGENT add column SERIALIZE char(1) default 'N' not null ",
            " update AGENT set SERIALIZE='N' ",
            " alter table AGENT alter column SERIALIZE drop default ",
    });

    log.debug("Updating version");
    st.executeUpdate("update SYSTEM_PROPERTY set VALUE = '" + upgraderVersion() + "' where NAME = 'parabuild.schema.version' ");

    // finish
    conn.commit();

  } finally {
    IoUtils.closeHard(st);
    conn.setAutoCommit(savedAutoCommit);
  }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:31,代码来源:UpgraderToVersion75.java

示例13: run

import java.sql.Connection; //导入方法依赖的package包/类
@Override
public void run() {
	Connection con = null;
	try {

		List<String> batch = getNextBatch();
		while (!batch.isEmpty()) {
			try {
				if (con == null || con.isClosed()) {
					con = conPool.getConnection();
					if (con.getAutoCommit() != autocommit) {
						con.setAutoCommit(autocommit);
					}
				}

				insert(con, batch);
				finshiedCount.addAndGet(batch.size());
			} catch (Exception e) {
				System.out.println("caught err in  thread :"
						+ Thread.currentThread().getId() + " " + e);
				try {
					con.rollback();
				} catch (SQLException e1) {
					System.out.println("caught err in thread :"
							+ Thread.currentThread().getId()
							+ " rollback err " + e1);
				}
				failedCount.addAndGet(batch.size());
			}
			batch = getNextBatch();
		}
	} finally {
		if (con != null) {
			this.conPool.returnCon(con);
		}
	}

}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:39,代码来源:UserTableInsertJob.java

示例14: upgrade

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Perform upgrade.
 */
public void upgrade(final Connection conn, final int upgradeToVersion) throws SQLException {
  final boolean savedAutoCommit = conn.getAutoCommit();
  Statement st = null; // NOPMD
  try {
    // create statement
    conn.setAutoCommit(true);
    st = conn.createStatement();

    LOG.debug("Altering table");
    PersistanceUtils.executeDDLs(st, new String[]{
      //
      " alter table PROMOTION_STEP add column LINE_NUMBER integer default 0 not null ",
      " update PROMOTION_STEP set LINE_NUMBER=ID ",
      " alter table PROMOTION_STEP alter column LINE_NUMBER drop default ",
      " create index PROMOTION_STEP_IX1 on PROMOTION_STEP(PROMOTION_POLICY_ID, LINE_NUMBER) ",
    });

    LOG.debug("Updating version");
    st.executeUpdate("update SYSTEM_PROPERTY set VALUE = '" + upgraderVersion() + "' where NAME = 'parabuild.schema.version' ");

    // finish
    conn.commit();

    // request post-startup config manager action
    System.setProperty(SystemConstants.SYSTEM_PROPERTY_INIT_ADVANCED_SETTINGS, "true");
  } finally {
    IoUtils.closeHard(st);
    conn.setAutoCommit(savedAutoCommit);
  }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:34,代码来源:UpgraderToVersion67.java

示例15: setAutoCommit

import java.sql.Connection; //导入方法依赖的package包/类
public void setAutoCommit(boolean autoCommit) throws SQLException {
    MC mc = getManagedConnection();
    if (mc.isInXaTransaction()) {
        throw new SQLException("Can not set autoCommit within an XA transaction");
    }
    Connection c = mc.getPhysicalConnection();
    if (autoCommit == c.getAutoCommit()) {
        // nothing to do
        return;
    }

    try {
        LocalTransaction tx = mc.getClientLocalTransaction();
        if (autoCommit) {
            // reenabling autoCommit - JDBC spec says current transaction is committed
            tx.commit();
        } else {
            // disabling autoCommit
            tx.begin();
        }
    } catch (ResourceException e) {
        if (e.getCause() instanceof SQLException) {
            throw (SQLException) e.getCause();
        } else {
            throw new SQLException(e);
        }
    }
}
 
开发者ID:ops4j,项目名称:org.ops4j.pax.transx,代码行数:29,代码来源:ConnectionHandle.java


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