本文整理汇总了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);
}
}
示例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);
}
}
示例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();
}
}
示例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();
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
}