Example usage for org.apache.commons.dbutils DbUtils closeQuietly

List of usage examples for org.apache.commons.dbutils DbUtils closeQuietly

Introduction

In this page you can find the example usage for org.apache.commons.dbutils DbUtils closeQuietly.

Prototype

public static void closeQuietly(Statement stmt) 

Source Link

Document

Close a Statement, avoid closing if null and hide any SQLExceptions that occur.

Usage

From source file:com.che.software.testato.domain.dao.jdbc.impl.ScriptItemDAO.java

/**
 * Script item search from a bean of criterions.
 * //from  w  w  w  .ja v  a  2 s  .  c  o m
 * @author Clement HELIOU (clement.heliou@che-software.com).
 * @param searchBean the criterions to use for the search.
 * @return the resulting object list.
 * @since July, 2011.
 * @throws ScriptItemSearchDAOException if an error occurs during the
 *         search.
 */
@Override
public List<ScriptItem> searchScriptItem(ScriptItemSearch searchBean) throws ScriptItemSearchDAOException {
    LOGGER.debug("searchScriptItem().");
    Connection connection = null;
    try {
        connection = getDataSource().getConnection();
        List<Object> params = new ArrayList<Object>();
        return getQueryRunner().query(connection, getScriptItemSearchQueryFromCriterion(searchBean, params),
                new BeanListHandler<ScriptItem>(ScriptItem.class), params.toArray());
    } catch (SQLException e) {
        throw new ScriptItemSearchDAOException(e);
    } finally {
        if (null != connection) {
            DbUtils.closeQuietly(connection);
        }
    }
}

From source file:com.che.software.testato.domain.dao.jdbc.impl.RandomIndexDAO.java

/**
 * Random index search from a bean of criterions.
 * //  w w  w . jav  a 2s  .  co  m
 * @author Clement HELIOU (clement.heliou@che-software.com).
 * @param searchBean the criterions to use for the search.
 * @return the resulting object list.
 * @since August, 2011.
 * @throws RandomIndexSearchDAOException if an error occurs during the
 *         search.
 */
@Override
public List<RandomIndex> searchRandomIndex(RandomIndexSearch searchBean) throws RandomIndexSearchDAOException {
    LOGGER.debug("searchRandomIndex().");
    Connection connection = null;
    try {
        connection = getDataSource().getConnection();
        List<Object> params = new ArrayList<Object>();
        return getQueryRunner().query(connection, getRandomIndexSearchQueryFromCriterion(searchBean, params),
                new BeanListHandler<RandomIndex>(RandomIndex.class), params.toArray());
    } catch (SQLException e) {
        throw new RandomIndexSearchDAOException(e);
    } finally {
        if (null != connection) {
            DbUtils.closeQuietly(connection);
        }
    }
}

From source file:com.che.software.testato.domain.dao.jdbc.impl.ProjectDAO.java

/**
 * Creates a project from his name.//from  ww  w . ja va 2  s  . c o  m
 * 
 * @author Clement HELIOU (clement.heliou@che-software.com).
 * @param name the name of the project to create.
 * @since July, 2011.
 * @throws ProjectCreationDAOException if an error occurs during the
 *         creation.
 */
@Override
public void createProjectFromName(String name) throws ProjectCreationDAOException {
    LOGGER.debug("createProjectFromName(" + name + ").");
    Connection connection = null;
    try {
        connection = getDataSource().getConnection();
        getQueryRunner().update(connection,
                "INSERT INTO project(project_id, \"name\") VALUES(nextval('project_seq'), ?) ",
                new Object[] { name });
    } catch (SQLException e) {
        throw new ProjectCreationDAOException(e);
    } finally {
        if (null != connection) {
            DbUtils.closeQuietly(connection);
        }
    }
}

From source file:com.splicemachine.derby.impl.sql.execute.operations.CallStatementOperationIT.java

@Test
public void testCallSqlColumns() throws Exception {
    int count = 0;
    DatabaseMetaData dmd = methodWatcher.getOrCreateConnection().getMetaData();
    ResultSet rs = dmd.getColumns(null, "SYS", "SYSSCHEMAS", null);
    Set<String> correctNames = Sets.newHashSet("SCHEMAID", "SCHEMANAME", "AUTHORIZATIONID");
    while (rs.next()) {
        String sIdCol = rs.getString(4);
        int colType = rs.getInt(5);
        Assert.assertTrue("No colType returned!", !rs.wasNull());
        int colNum = rs.getInt(17);
        Assert.assertTrue("No colNum returned!", !rs.wasNull());

        Assert.assertTrue("Incorrect column name returned!", correctNames.contains(sIdCol.toUpperCase()));
        count++;//from ww  w  . ja va 2s  .co m
    }
    Assert.assertEquals("incorrect rows returned!", 3, count);
    DbUtils.closeQuietly(rs);
}

From source file:com.intelligentz.appointmentz.controllers.register.java

private void register(String id, String userName, String password, String hospitalName, HttpServletRequest req,
        HttpServletResponse res) throws IOException {
    boolean status = false;
    try {//from   w ww . j  a v a2  s . com
        connection = DBConnection.getDBConnection().getConnection();
        String SQL1 = "insert into hospital (id,hospital_id, hospital_name, password) VALUES (?,?,?,?)";

        preparedStatement = connection.prepareStatement(SQL1);
        preparedStatement.setString(1, id);
        preparedStatement.setString(2, userName);
        preparedStatement.setString(3, hospitalName);
        preparedStatement.setString(4, password);
        preparedStatement.executeUpdate();

        res.sendRedirect("./index.jsp?register=successfully registered");

    } catch (SQLException | IOException | PropertyVetoException ex) {
        LOGGER.log(Level.SEVERE, ex.toString(), ex);
        res.sendRedirect("./register.jsp?register=failed");
    } finally {
        try {
            DbUtils.closeQuietly(resultSet);
            DbUtils.closeQuietly(preparedStatement);
            DbUtils.close(connection);
        } catch (SQLException ex) {
            Logger.getLogger(register.class.getName()).log(Level.SEVERE, ex.toString(), ex);
        }
    }
}

From source file:azkaban.trigger.JdbcTriggerLoaderTest.java

public void setupDB() {
    DataSource dataSource = DataSourceUtils.getMySQLDataSource(host, port, database, user, password,
            numConnections);/*from w ww  .  ja  va2 s.c o  m*/
    testDBExists = true;

    Connection connection = null;
    try {
        connection = dataSource.getConnection();
    } catch (SQLException e) {
        e.printStackTrace();
        testDBExists = false;
        DbUtils.closeQuietly(connection);
        return;
    }

    CountHandler countHandler = new CountHandler();
    QueryRunner runner = new QueryRunner();
    try {
        runner.query(connection, "SELECT COUNT(1) FROM triggers", countHandler);
    } catch (SQLException e) {
        e.printStackTrace();
        testDBExists = false;
        DbUtils.closeQuietly(connection);
        return;
    }

    DbUtils.closeQuietly(connection);

    clearDB();
}

From source file:com.splicemachine.derby.test.framework.SpliceTableWatcher.java

public void importData(String filename, String timestamp) {
    Connection connection = null;
    PreparedStatement ps = null;//from ww w .java2 s .co  m
    try {
        connection = SpliceNetConnection.getConnection();
        ps = connection.prepareStatement(
                "call SYSCS_UTIL.IMPORT_DATA (?, ?, null,?,',',null,?,null,null,0,null,true,null)");
        ps.setString(1, schemaName);
        ps.setString(2, tableName);
        ps.setString(3, filename);
        ps.setString(4, timestamp);
        ps.executeQuery();
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        DbUtils.closeQuietly(ps);
        DbUtils.commitAndCloseQuietly(connection);
    }
}

From source file:com.gs.obevo.db.apps.reveng.CsvStaticDataWriterTest.java

@After
public void teardown() throws Exception {
    DbUtils.closeQuietly(conn);
}

From source file:com.ouc.cpss.dao.BaseDao.java

/**
 * ?/* w w  w .  j  ava  2  s  . c o  m*/
 *
 * @param sql
 * @param clazz
 * @return
 */
public List query(String sql, Class clazz, Object[] params) {
    List beans = null;
    Connection conn = null;
    try {
        conn = getConnection();
        QueryRunner qRunner = new QueryRunner();
        beans = (List) qRunner.query(conn, sql, new BeanListHandler(clazz), params);

        //BeanListHandler?ResultSet???List?
        //????ResultSet
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        DbUtils.closeQuietly(conn);
    }
    return beans;
}

From source file:com.manydesigns.portofino.database.platforms.GoogleCloudSQLDatabasePlatform.java

public List<String> getSchemaNames(DatabaseMetaData databaseMetaData) throws SQLException {
    ResultSet rs = databaseMetaData.getCatalogs();
    List<String> schemaNames = new ArrayList<String>();
    try {/*from   w  w  w.  ja  v  a 2s  .  c o m*/
        while (rs.next()) {
            String schemaName = rs.getString(TABLE_CAT);
            schemaNames.add(schemaName);
        }
    } finally {
        DbUtils.closeQuietly(rs);
    }
    return schemaNames;
}