本文整理汇总了Java中org.apache.ibatis.jdbc.ScriptRunner.setAutoCommit方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptRunner.setAutoCommit方法的具体用法?Java ScriptRunner.setAutoCommit怎么用?Java ScriptRunner.setAutoCommit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ibatis.jdbc.ScriptRunner
的用法示例。
在下文中一共展示了ScriptRunner.setAutoCommit方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeSqlScript
import org.apache.ibatis.jdbc.ScriptRunner; //导入方法依赖的package包/类
/**
*
* @param connection
* @param in
* @throws Exception
*/
public static void executeSqlScript(Connection connection, InputStream in) throws Exception {
if (null == connection || null == in) {
return;
}
ScriptRunner runner = new ScriptRunner(connection);
runner.setAutoCommit(true);
Reader reader = null;
try {
reader = new InputStreamReader(in, "utf-8"); //$NON-NLS-1$
runner.runScript(reader);
} catch (Throwable e) {
throw new Exception("An error occured while try to execute SQL script.", e);
} finally {
IOUtils.closeQuietly(reader);
IOUtils.closeQuietly(in);
runner.closeConnection();
}
}
示例2: run
import org.apache.ibatis.jdbc.ScriptRunner; //导入方法依赖的package包/类
private void run() throws IOException, SQLException {
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setUrl("jdbc:mysql://" + host + ":" + port + "/" + database);
dataSource.setUser(username);
dataSource.setPassword(password);
try (FileInputStream inputStream = new FileInputStream(file)) {
ScriptRunner runner = new ScriptRunner(dataSource.getConnection());
runner.setAutoCommit(true);
runner.setStopOnError(true);
runner.runScript(new InputStreamReader(inputStream));
runner.closeConnection();
}
}
示例3: afterStart
import org.apache.ibatis.jdbc.ScriptRunner; //导入方法依赖的package包/类
@Override
public void afterStart() {
/*
测试的数据库(启动后创建)
*/
Reader config = null;
Reader sql = null;
SqlSession sqlSession = null;
try {
config = Resources.getResourceAsReader("mybatis-config.xml");
SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(config);
sqlSession = sessionFactory.openSession(true);
Connection connection = sqlSession.getConnection();
ScriptRunner runner = new ScriptRunner(connection);
runner.setAutoCommit(true);
sql = Resources.getResourceAsReader("easycontroller.sql");
runner.runScript(sql);
runner.closeConnection();
} catch (Exception e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(sqlSession);
IOUtils.closeQuietly(sql);
IOUtils.closeQuietly(config);
}
}
示例4: runScript
import org.apache.ibatis.jdbc.ScriptRunner; //导入方法依赖的package包/类
public static void runScript(DataSource ds, String resource) throws IOException, SQLException {
Connection connection = ds.getConnection();
try {
ScriptRunner runner = new ScriptRunner(connection);
runner.setAutoCommit(true);
runner.setStopOnError(false);
runner.setLogWriter(null);
runner.setErrorLogWriter(null);
runScript(runner, resource);
} finally {
connection.close();
}
}
示例5: runReaderScript
import org.apache.ibatis.jdbc.ScriptRunner; //导入方法依赖的package包/类
private static void runReaderScript(Connection conn, SqlSession session, Reader reader) throws Exception {
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.setSendFullScript(true);
runner.setAutoCommit(true);
runner.setStopOnError(false);
runner.runScript(reader);
}
示例6: runScript
import org.apache.ibatis.jdbc.ScriptRunner; //导入方法依赖的package包/类
public static void runScript(DataSource ds, String resource) throws IOException, SQLException {
Connection connection = ds.getConnection();
try {
ScriptRunner runner = new ScriptRunner(connection);
runner.setAutoCommit(true);
runner.setStopOnError(false);
runner.setLogWriter(null);
runner.setErrorLogWriter(null);
runScript(runner, resource);
} finally {
connection.close();
}
}
示例7: runScript
import org.apache.ibatis.jdbc.ScriptRunner; //导入方法依赖的package包/类
public static void runScript(DataSource ds, String resource)
throws IOException, SQLException {
Connection connection = ds.getConnection();
try {
ScriptRunner runner = new ScriptRunner(connection);
runner.setAutoCommit(true);
runner.setStopOnError(false);
runner.setLogWriter(new PrintWriter(System.out));
runner.setErrorLogWriter(new PrintWriter(System.err));
runScript(runner, resource);
} finally {
connection.close();
}
}
示例8: executeSQL
import org.apache.ibatis.jdbc.ScriptRunner; //导入方法依赖的package包/类
private void executeSQL(Connection connection, Reader reader) throws SQLException {
ScriptRunner runner = new ScriptRunner(connection);
runner.setAutoCommit(true);
runner.setStopOnError(true);
try {
runner.runScript(reader);
} catch (RuntimeSqlException e) {
throw new SQLException(e); // Force to handle the exception by myself
}
}
示例9: loadInitializeData
import org.apache.ibatis.jdbc.ScriptRunner; //导入方法依赖的package包/类
@SneakyThrows
private static void loadInitializeData(Injector injector, Reader reader) {
DataSource dataSource = injector.getInstance(DataSource.class);
try (final Connection connection = dataSource.getConnection()) {
ScriptRunner runner = new ScriptRunner(connection);
runner.setAutoCommit(true);
runner.setStopOnError(true);
runner.runScript(reader);
} // Auto close connection
}