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:com.plexobject.testplayer.dao.jdbc.JdbcUtil.java

static void attemptClose(Statement o) {
    try {/*from   w w  w  .  j  a va  2s  .  com*/
        if (o != null)
            o.close();
    } catch (Exception e) {
        log.error("Failed to close " + o, e);
    }
}

From source file:com.ibm.research.rdf.store.jena.impl.DB2CloseObjects.java

public static void close(Statement statement) {
    if (statement != null) {
        try {//from   w w w.ja v a2 s .c  o  m
            //if (!statement.isClosed()) {
            statement.close();
            //}
        } catch (SQLException e) {
            log.error("Unexpected SQLException while closing statement..", e);
        }
    }
}

From source file:Main.java

/**
 * Helper method to create a Redshift table
 * /*  ww w .  j a  v a 2s.  c om*/
 * @param redshiftURL
 *            The JDBC URL of the Redshift database
 * @param loginProperties
 *            A properties file containing the authentication credentials for the database
 * @param tableName
 *            The table to create
 * @param fields
 *            A list of column specifications that will be comma separated in the create table
 *            statement
 * @throws SQLException
 *             Table creation failed
 */
public static void createRedshiftTable(String redshiftURL, Properties loginProperties, String tableName,
        List<String> fields) throws SQLException {
    Connection conn = DriverManager.getConnection(redshiftURL, loginProperties);
    Statement stmt = conn.createStatement();
    stmt.execute("CREATE TABLE " + tableName + " " + toSQLFields(fields) + ";");
    stmt.close();
    conn.close();
}

From source file:at.molindo.dbcopy.util.Utils.java

public static void close(Statement ps) {
    if (ps != null) {
        try {//from  w  ww  . j  a  va 2  s .c om
            ps.close();
        } catch (SQLException e) {
            log.warn("failed to close statement");
        }
    }
}

From source file:cn.vlabs.umt.common.datasource.DatabaseUtil.java

/**
 * Statement?????/*from   www .  j  a v  a2 s. c  om*/
 * @param st Statement
 */
public static void closeStatement(Statement st) {
    if (st != null) {
        try {
            st.close();
        } catch (SQLException e) {
            log.error(st, e);
        }
    }
}

From source file:Main.java

public static void close(Statement st) {
    try {//ww  w  .j a va 2s  .c  o  m
        if (st != null) {
            st.close();
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * Safely close a JDBC Statement, absorbing exceptions and handling
 * <code>null</code> graciously.
 * //from   ww  w . j  a  va2  s  .  c o m
 * @param statement
 *            to close.
 */
public static void safeClose(Statement statement) {
    try {
        if (statement != null) {
            statement.close();
        }
    } catch (SQLException e) {
        log(statement, e);
    }
}

From source file:com.nabla.wapp.server.database.Database.java

public static void close(final Statement stmt) {
    try {//from w w w . j  ava 2  s.c o m
        stmt.close();
    } catch (final SQLException e) {
    }
}

From source file:com.googlecode.flyway.core.util.jdbc.JdbcUtils.java

/**
 * Safely closes this statement. This method never fails.
 *
 * @param statement The statement to close.
 *//*from  w  w w .j ava2s . c om*/
public static void closeStatement(Statement statement) {
    if (statement == null) {
        return;
    }

    try {
        statement.close();
    } catch (SQLException e) {
        LOG.error("Error while closing Jdbc statement", e);
    }
}

From source file:com.amazonaws.services.cognito.streams.connector.AmazonCognitoStreamsEnvironmentOptions.java

static void createRedshiftTable(Properties properties) {
    // Ensure our data table exists
    Properties loginProperties = new Properties();
    loginProperties.setProperty("user", getRedshiftUserName());
    loginProperties.setProperty("password", getRedshiftPassword());

    StringBuilder builder = new StringBuilder();
    builder.append("CREATE TABLE IF NOT EXISTS ")
            .append(properties.getProperty(KinesisConnectorConfiguration.PROP_REDSHIFT_DATA_TABLE)).append(" (")
            .append("identityPoolId varchar(128),").append("identityId varchar(128),")
            .append("datasetName varchar(128),").append("operation varchar(64),").append("key varchar(1024),")
            .append("value varchar(4096),").append("op varchar(64),").append("syncCount int,")
            .append("deviceLastModifiedDate timestamp,").append("lastModifiedDate timestamp").append(")");

    Connection conn = null;//from   w  w  w .  j  ava 2 s  .c  om
    try {
        conn = DriverManager.getConnection(getJDBCConnection(), loginProperties);

        Statement stmt = conn.createStatement();
        stmt.execute(builder.toString());
        stmt.close();
    } catch (SQLException e) {
        LOG.error("Failed to create table.", e);
    } finally {
        try {
            conn.close();
        } catch (SQLException e) {
            LOG.error("Failed close connection.", e);
        }
    }
}