Code example for Connection

Methods: toStringcreateStruct

0
    protected void checkOpen() throws SQLException { 
        if(_closed) {
            if (null != _conn) {
                String label = "";
                try { 
                    label = _conn.toString();
                } catch (Exception ex) {
                    // ignore, leave label empty 
                } 
                throw new SQLException
                    ("Connection " + label + " is closed.");
            } else { 
                throw new SQLException
                    ("Connection is null."); 
            } 
        } 
    } 
 
    protected void activate() { 
        _closed = false;
        setLastUsed(); 
        if(_conn instanceof DelegatingConnection) {
            ((DelegatingConnection<?>)_conn).activate();
        } 
    } 
 
    protected void passivate() throws SQLException { 
        // The JDBC spec requires that a Connection close any open 
        // Statement's when it is closed. 
        // DBCP-288. Not all the traced objects will be statements 
        List<AbandonedTrace> traces = getTrace();
        if(traces != null) {
            Iterator<AbandonedTrace> traceIter = traces.iterator();
            while (traceIter.hasNext()) {
                Object trace = traceIter.next();
                if (trace instanceof Statement) {
                    ((Statement) trace).close();
                } else if (trace instanceof ResultSet) {
                    // DBCP-265: Need to close the result sets that are 
                    // generated via DatabaseMetaData 
                    ((ResultSet) trace).close();
                } 
            } 
            clearTrace(); 
        } 
        setLastUsed(0); 
    } 
 
 
    @Override 
    public int getHoldability() throws SQLException { 
        checkOpen(); 
        try { 
            return _conn.getHoldability();
        } catch (SQLException e) {
            handleException(e);
            return 0; 
        } 
    } 
 
 
    @Override 
    public void setHoldability(int holdability) throws SQLException {
        checkOpen(); 
        try { 
            _conn.setHoldability(holdability);
        } catch (SQLException e) {
            handleException(e);
        } 
    } 
 
 
    @Override 
    public Savepoint setSavepoint() throws SQLException {
        checkOpen(); 
        try { 
            return _conn.setSavepoint();
        } catch (SQLException e) {
            handleException(e);
            return null; 
        } 
    } 
 
 
    @Override 
    public Savepoint setSavepoint(String name) throws SQLException {
        checkOpen(); 
        try { 
            return _conn.setSavepoint(name);
        } catch (SQLException e) {
            handleException(e);
            return null; 
        } 
    } 
 
 
    @Override 
    public void rollback(java.sql.Savepoint savepoint) throws SQLException {
        checkOpen(); 
        try { 
            _conn.rollback(savepoint);
        } catch (SQLException e) {
            handleException(e);
        } 
    } 
 
 
    @Override 
    public void releaseSavepoint(java.sql.Savepoint savepoint)
            throws SQLException { 
        checkOpen(); 
        try { 
            _conn.releaseSavepoint(savepoint);
        } catch (SQLException e) {
            handleException(e);
        } 
    } 
 
 
    @Override 
    public Statement createStatement(int resultSetType,
                                     int resultSetConcurrency,
                                     int resultSetHoldability) throws SQLException {
        checkOpen(); 
        try { 
            return new DelegatingStatement(this, _conn.createStatement(
                resultSetType, resultSetConcurrency, resultSetHoldability));
        } 
        catch (SQLException e) {
            handleException(e);
            return null; 
        } 
    } 
 
    @Override 
    public PreparedStatement prepareStatement(String sql, int resultSetType,
                                              int resultSetConcurrency,
                                              int resultSetHoldability) throws SQLException {
        checkOpen(); 
        try { 
            return new DelegatingPreparedStatement(this, _conn.prepareStatement(
                sql, resultSetType, resultSetConcurrency, resultSetHoldability));
        } 
        catch (SQLException e) {
            handleException(e);
            return null; 
        } 
    } 
 
    @Override 
    public CallableStatement prepareCall(String sql, int resultSetType,
                                         int resultSetConcurrency,
                                         int resultSetHoldability) throws SQLException {
        checkOpen(); 
        try { 
            return new DelegatingCallableStatement(this, _conn.prepareCall(
                sql, resultSetType, resultSetConcurrency, resultSetHoldability));
        } 
        catch (SQLException e) {
            handleException(e);
            return null; 
        } 
    } 
 
    @Override 
    public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
        checkOpen(); 
        try { 
            return new DelegatingPreparedStatement(this, _conn.prepareStatement(
                sql, autoGeneratedKeys));
        } 
        catch (SQLException e) {
            handleException(e);
            return null; 
        } 
    } 
 
    @Override 
    public PreparedStatement prepareStatement(String sql, int columnIndexes[]) throws SQLException {
        checkOpen(); 
        try { 
            return new DelegatingPreparedStatement(this, _conn.prepareStatement(
                sql, columnIndexes));
        } 
        catch (SQLException e) {
            handleException(e);
            return null; 
        } 
    } 
 
    @Override 
    public PreparedStatement prepareStatement(String sql, String columnNames[]) throws SQLException {
        checkOpen(); 
        try { 
            return new DelegatingPreparedStatement(this, _conn.prepareStatement(
                sql, columnNames));
        } 
        catch (SQLException e) {
            handleException(e);
            return null; 
        } 
    } 
 
/* JDBC_4_ANT_KEY_BEGIN */ 
 
    @Override 
    public boolean isWrapperFor(Class<?> iface) throws SQLException {
        if (iface.isAssignableFrom(getClass())) {
            return true; 
        } else if (iface.isAssignableFrom(_conn.getClass())) {
            return true; 
        } else { 
            return _conn.isWrapperFor(iface);
        } 
    } 
 
    @Override 
    public <T> T unwrap(Class<T> iface) throws SQLException {
        if (iface.isAssignableFrom(getClass())) {
            return iface.cast(this);
        } else if (iface.isAssignableFrom(_conn.getClass())) {
            return iface.cast(_conn);
        } else { 
            return _conn.unwrap(iface);
        } 
    } 
 
    @Override 
    public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
        checkOpen(); 
        try { 
            return _conn.createArrayOf(typeName, elements);
        } 
        catch (SQLException e) {
            handleException(e);
            return null; 
        } 
    } 
 
    @Override 
    public Blob createBlob() throws SQLException {
        checkOpen(); 
        try { 
            return _conn.createBlob();
        } 
        catch (SQLException e) {
            handleException(e);
            return null; 
        } 
    } 
 
    @Override 
    public Clob createClob() throws SQLException {
        checkOpen(); 
        try { 
            return _conn.createClob();
        } 
        catch (SQLException e) {
            handleException(e);
            return null; 
        } 
    } 
 
    @Override 
    public NClob createNClob() throws SQLException {
        checkOpen(); 
        try { 
            return _conn.createNClob();
        } 
        catch (SQLException e) {
            handleException(e);
            return null; 
        } 
    } 
 
    @Override 
    public SQLXML createSQLXML() throws SQLException {
        checkOpen(); 
        try { 
            return _conn.createSQLXML();
        } 
        catch (SQLException e) {
            handleException(e);
            return null; 
        } 
    } 
 
    @Override 
    public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
        checkOpen(); 
        try { 
            return _conn.createStruct(typeName, attributes);
        } 
        catch (SQLException e) {
            handleException(e);
            return null; 
        }