Example usage for java.sql Statement close

List of usage examples for java.sql Statement close

Introduction

In this page you can find the example usage for java.sql Statement close.

Prototype

void close() throws SQLException;

Source Link

Document

Releases this Statement object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed.

Usage

From source file:de.langmi.spring.batch.examples.readers.support.CompositeCursorItemReaderTest.java

/**
 * Properly tears down a HSQLDB in-memory database.
 *
 * @param dataSource/*from w  w  w  .  j  av  a  2s  .  c  om*/
 * @throws Exception 
 */
private void tearDownDataSource(final DataSource dataSource) throws Exception {
    Connection conn = dataSource.getConnection();
    Statement st = conn.createStatement();
    st.execute("SHUTDOWN");
    conn.commit();
    st.close();
}

From source file:be.fgov.kszbcss.rhq.websphere.component.jdbc.db2.pool.ConnectionContextImpl.java

void testConnection() throws SQLException {
    execute(new Query<Void>() {
        public Void execute(Connection connection) throws SQLException {
            Statement statement = connection.createStatement();
            try {
                statement.execute("SELECT 1 FROM SYSIBM.SYSDUMMY1");
            } finally {
                statement.close();
            }//from w w w .  ja v a2s  . c o m
            return null;
        }
    });
}

From source file:net.duckling.falcon.api.boostrap.BootstrapDao.java

private void closeAll(Connection conn, Statement stmt, ResultSet rs) throws SQLException {
    if (rs != null) {
        rs.close();// w w  w.  j  a v  a 2s  . c om
    }
    if (stmt != null) {
        stmt.close();
    }
    if (conn != null) {
        conn.close();
    }
}

From source file:org.web4thejob.module.JobletInstallerImpl.java

@Override
@SuppressWarnings("unchecked")
public <E extends Exception> List<E> install(List<Joblet> joblets) {
    List<E> exceptions = new ArrayList<E>();

    try {//ww w  . java2s  .c om

        final Configuration configuration = new Configuration();
        configuration.setProperty(AvailableSettings.DIALECT,
                connInfo.getProperty(DatasourceProperties.DIALECT));
        configuration.setProperty(AvailableSettings.DRIVER, connInfo.getProperty(DatasourceProperties.DRIVER));
        configuration.setProperty(AvailableSettings.URL, connInfo.getProperty(DatasourceProperties.URL));
        configuration.setProperty(AvailableSettings.USER, connInfo.getProperty(DatasourceProperties.USER));
        configuration.setProperty(AvailableSettings.PASS, connInfo.getProperty(DatasourceProperties.PASSWORD));

        final ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
                .applySettings(configuration.getProperties()).build();

        if (StringUtils.hasText(connInfo.getProperty(DatasourceProperties.SCHEMA_SYNTAX))) {
            String schemaSyntax = connInfo.getProperty(DatasourceProperties.SCHEMA_SYNTAX);
            Connection connection = serviceRegistry.getService(ConnectionProvider.class).getConnection();

            for (Joblet joblet : joblets) {
                for (String schema : joblet.getSchemas()) {
                    Statement statement = connection.createStatement();
                    statement.executeUpdate(schemaSyntax.replace("%s", schema));
                    statement.close();
                }
            }

            if (!connection.getAutoCommit()) {
                connection.commit();
            }
        }

        for (Joblet joblet : joblets) {
            for (Resource resource : joblet.getResources()) {
                configuration.addInputStream(resource.getInputStream());
            }
        }

        SchemaExport schemaExport = new SchemaExport(serviceRegistry, configuration);
        schemaExport.execute(Target.EXPORT, SchemaExport.Type.CREATE);
        exceptions.addAll(schemaExport.getExceptions());

    } catch (Exception e) {
        exceptions.add((E) e);
    }

    return exceptions;

}

From source file:TestAppletNetscape.java

public void paint(Graphics g) {
    System.out.println("paint(): querying the database");
    try {//w  w w  . j a  v  a  2 s  . c  o  m
        PrivilegeManager.enablePrivilege("UniversalConnect");
        Statement stmt = conn.createStatement();
        ResultSet rset = stmt.executeQuery("select 'Hello '||initcap(USER) result from dual");
        while (rset.next())
            g.drawString(rset.getString(1), 10, 10);
        rset.close();
        stmt.close();
    } catch (SQLException e) {
        System.err.println("paint(): SQLException: " + e.getMessage());
    }
}

From source file:cc.osint.graphd.db.SQLDB.java

public void update(String expression) throws Exception {
    log.info("update(" + expression + ")");
    Statement st = null;
    st = conn.createStatement();/*  ww  w  .j a  v a2s  . c o  m*/
    int i = st.executeUpdate(expression);
    if (i == -1) {
        log.info("db error: " + expression);
        throw new Exception("db error: " + expression);
    }
    st.close();
}

From source file:info.jtrac.config.DataSourceFactoryBean.java

/**
 * This method is called to clean up the references when the object is
 * destroyed./*from   w ww  . j a v a2  s . co  m*/
 *
 * @throws Exception
 * @see org.springframework.beans.factory.DisposableBean#destroy()
 */
@Override
public void destroy() throws Exception {
    if (dataSource instanceof SingleConnectionDataSource) {
        logger.info("attempting to shut down embedded HSQLDB database");
        Connection con = dataSource.getConnection();
        Statement stmt = con.createStatement();
        stmt.executeUpdate("SHUTDOWN");
        stmt.close();
        con.close();
        logger.info("embedded HSQLDB database shut down successfully");
    } else if (dataSource instanceof BasicDataSource) {
        logger.info("attempting to close Apache DBCP data source");
        ((BasicDataSource) dataSource).close();
        logger.info("Apache DBCP data source closed successfully");
    } else {
        logger.info("context shutting down for JNDI datasource");
    } // end if..else
}

From source file:com.thoughtworks.go.server.database.H2Database.java

public void shutdown() throws SQLException {
    if (systemEnvironment.inDbDebugMode()) {
        LOG.info("Shutting down database server.");
        if (tcpServer == null) {
            return;
        }// w  w w  .j a  v  a2  s  .  c  o m
        if (dataSource != null) {
            dataSource.close();
        }
        dataSource = null;
        tcpServer.stop();
        tcpServer = null;
    } else {
        Connection connection = createDataSource().getConnection();
        Statement statement = connection.createStatement();
        statement.execute("SHUTDOWN");
        statement.close();
        dataSource.close();
        dataSource = null;
    }
}

From source file:com.consol.citrus.samples.todolist.dao.JdbcTodoListDao.java

@Override
public void deleteAll() {
    try {//from  w w  w .jav  a2 s.  c om
        Connection connection = getConnection();
        try {
            Statement statement = connection.createStatement();
            try {
                statement.executeQuery("DELETE FROM todo_entries");
            } finally {
                statement.close();
            }
        } finally {
            connection.close();
        }
    } catch (SQLException e) {
        throw new DataAccessException("Could not delete entries", e);
    }
}

From source file:com.emergya.persistenceGeo.dbutils.DatabaseUtilsImpl.java

private void changeColumnName(String tableName, String oldName, String newName) throws SQLException {
    Connection con = ds.getConnection();
    Statement stm = con.createStatement();
    String sql = "ALTER TABLE " + tableName + " RENAME COLUMN " + oldName + " TO " + newName;
    stm.executeUpdate(sql);/*w  w  w . j  av  a2 s . c  o  m*/
    stm.close();
    con.close();

}