List of usage examples for org.apache.commons.dbutils DbUtils commitAndCloseQuietly
public static void commitAndCloseQuietly(Connection conn)
Connection
then closes it, avoid closing if null and hide any SQLExceptions that occur. From source file:jp.co.golorp.emarf.sql.Connections.java
/** * /*www . j a v a2 s . c o m*/ */ public static void commit() { Connection cn = threadLocalConnection.get(); LOG.debug("commit connection."); DbUtils.commitAndCloseQuietly(cn); }
From source file:com.splicemachine.derby.test.framework.SpliceUserWatcher.java
@Override protected void starting(Description description) { Connection connection = null; Statement statement = null;//from w w w .j av a 2s . com ResultSet rs = null; try { dropAndCreateUser(userName, password); } catch (Exception e) { throw new RuntimeException(e); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(statement); DbUtils.commitAndCloseQuietly(connection); } super.starting(description); }
From source file:com.splicemachine.derby.test.framework.SpliceRoleWatcher.java
@Override protected void starting(Description description) { LOG.trace("Starting"); executeDrop(roleName.toUpperCase()); Connection connection = null; Statement statement = null;/*from w ww .j a va 2 s . c o m*/ ResultSet rs = null; try { connection = SpliceNetConnection.getConnection(); statement = connection.createStatement(); statement.execute(String.format("create role %s", roleName)); connection.commit(); } catch (Exception e) { LOG.error("Role statement is invalid "); e.printStackTrace(); throw new RuntimeException(e); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(statement); DbUtils.commitAndCloseQuietly(connection); } super.starting(description); }
From source file:com.splicemachine.derby.test.framework.SpliceRoleWatcher.java
public static void executeDrop(String roleName) { LOG.trace("ExecuteDrop"); Connection connection = null; PreparedStatement statement = null; try {/*from w ww. jav a 2 s . c om*/ connection = SpliceNetConnection.getConnection(); statement = connection.prepareStatement("select roleid from sys.sysroles where roleid = ?"); statement.setString(1, roleName); ResultSet rs = statement.executeQuery(); if (rs.next()) connection.createStatement().execute(String.format("drop role %s", roleName)); connection.commit(); } catch (Exception e) { LOG.error("error Dropping " + e.getMessage()); e.printStackTrace(); throw new RuntimeException(e); } finally { DbUtils.closeQuietly(statement); DbUtils.commitAndCloseQuietly(connection); } }
From source file:com.splicemachine.derby.test.framework.SpliceGrantWatcher.java
@Override protected void starting(Description description) { LOG.trace("Starting"); Connection connection = null; Statement statement = null;/*from w ww . ja v a 2 s . c o m*/ ResultSet rs = null; try { connection = userName == null ? SpliceNetConnection.getConnection() : SpliceNetConnection.getConnectionAs(userName, password); statement = connection.createStatement(); statement.execute(createString); connection.commit(); } catch (Exception e) { LOG.error("Grant statement is invalid "); e.printStackTrace(); throw new RuntimeException(e); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(statement); DbUtils.commitAndCloseQuietly(connection); } super.starting(description); }
From source file:com.splicemachine.derby.test.framework.SpliceTableWatcher.java
public void importData(String filename) { Connection connection = null; PreparedStatement ps = null;// w w w . j a v a2 s. c om try { connection = SpliceNetConnection.getConnection(); ps = connection.prepareStatement( "call SYSCS_UTIL.IMPORT_DATA (?, ?, null,?,',',null,null,null,null,1,null,true,'utf-8')"); ps.setString(1, schemaName); ps.setString(2, tableName); ps.setString(3, filename); try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { } } } catch (Exception e) { throw new RuntimeException(e); } finally { DbUtils.closeQuietly(ps); DbUtils.commitAndCloseQuietly(connection); } }
From source file:com.splicemachine.derby.test.framework.SpliceUserWatcher.java
public void createUser(String userName, String password) { Connection connection = null; PreparedStatement statement = null; try {/*from w w w. j a v a2 s . c o m*/ connection = SpliceNetConnection.getConnection(); statement = connection.prepareStatement("call syscs_util.syscs_create_user(?,?)"); statement.setString(1, userName); statement.setString(2, password); statement.execute(); } catch (Exception e) { LOG.error("error Creating " + e.getMessage()); e.printStackTrace(); throw new RuntimeException(e); } finally { DbUtils.closeQuietly(statement); DbUtils.commitAndCloseQuietly(connection); } }
From source file:com.splicemachine.derby.test.framework.SpliceFunctionWatcher.java
public static void executeDrop(String schemaName, String functionName) { LOG.trace("executeDrop"); Connection connection = null; Statement statement = null;/*from ww w . j ava2 s.c om*/ try { connection = SpliceNetConnection.getConnection(); statement = connection.createStatement(); statement.execute("drop function " + schemaName.toUpperCase() + "." + functionName.toUpperCase()); connection.commit(); } catch (Exception e) { LOG.error("error Dropping " + e.getMessage()); e.printStackTrace(); throw new RuntimeException(e); } finally { DbUtils.closeQuietly(statement); DbUtils.commitAndCloseQuietly(connection); } }
From source file:com.splicemachine.derby.test.framework.SpliceFunctionWatcher.java
@Override protected void starting(Description description) { LOG.trace("Starting"); Connection connection = null; Statement statement = null;/*from w w w .j av a 2s . c om*/ ResultSet rs = null; try { connection = (userName == null) ? SpliceNetConnection.getConnection() : SpliceNetConnection.getConnectionAs(userName, password); rs = connection.getMetaData().getTables(null, schemaName, functionName, null); if (rs.next()) { executeDrop(schemaName, functionName); } connection.commit(); statement = connection.createStatement(); statement.execute(CREATE_FUNCTION + schemaName + "." + functionName + " " + createString); connection.commit(); } catch (Exception e) { LOG.error("Create function statement is invalid "); e.printStackTrace(); throw new RuntimeException(e); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(statement); DbUtils.commitAndCloseQuietly(connection); } super.starting(description); }
From source file:com.splicemachine.derby.test.framework.SpliceViewWatcher.java
public static void executeDrop(String schemaName, String viewName) { LOG.trace("executeDrop"); Connection connection = null; Statement statement = null;/*from w w w . j a v a 2 s .c om*/ try { connection = SpliceNetConnection.getConnection(); statement = connection.createStatement(); statement.execute("drop view " + schemaName.toUpperCase() + "." + viewName.toUpperCase()); connection.commit(); } catch (Exception e) { LOG.error("error Dropping " + e.getMessage()); e.printStackTrace(System.err); throw new RuntimeException(e); } finally { DbUtils.closeQuietly(statement); DbUtils.commitAndCloseQuietly(connection); } }