Java Code Examples for java.sql.Statement.isClosed()

The following are Jave code examples for showing how to use isClosed() of the java.sql.Statement class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: ats-framework   File: DbUtils.java   Source Code and License Vote up 6 votes
/**
 * Closes JDBC statement and open ResultSet without throwing exception. If there is one it is just logged.
 */
public static void closeStatement(
                                   Statement statement ) {

    if (statement == null) {
        return;
    }
    try {
        boolean isClosed;
        try {
            isClosed = statement.isClosed();
        } catch (AbstractMethodError err) {
            isClosed = false; // no JavaSE 6-compatible driver
        }
        if (statement != null && !isClosed) {
            statement.close();
        }
    } catch (SQLException e) {
        log.error(getFullSqlException("Could not close SQL statement", e));
    }
}
 
Example 2
Project: ClassroomFlipkart   File: DBUtils.java   Source Code and License Vote up 6 votes
public static void closeStatement(Statement stmt){
    try{
        if(stmt != null && !stmt.isClosed()){
            stmt.close();
        }
    }catch(Exception e){
        //
    }
}
 
Example 3
Project: neoscada   File: BaseStorageDao.java   Source Code and License Vote up 5 votes
public void closeStatement ( final Statement statement )
{
    try
    {
        if ( statement == null || statement.isClosed () )
        {
            return;
        }
        statement.close ();
    }
    catch ( final SQLException e )
    {
        logger.debug ( "Exception on closing statement", e );
    }
}
 
Example 4
Project: SkyWarsReloaded   File: Database.java   Source Code and License Vote up 5 votes
public void createTables() throws IOException, SQLException {
    URL resource = Resources.getResource(SkyWarsReloaded.class, "/tables.sql");
    String[] databaseStructure = Resources.toString(resource, Charsets.UTF_8).split(";");

    if (databaseStructure.length == 0) {
        return;
    }

    Statement statement = null;

    try {
        connection.setAutoCommit(false);
        statement = connection.createStatement();

        for (String query : databaseStructure) {
            query = query.trim();

            if (query.isEmpty()) {
                continue;
            }

            statement.execute(query);
        }

        connection.commit();

    } finally {
        connection.setAutoCommit(true);

        if (statement != null && !statement.isClosed()) {
            statement.close();
        }
    }
}