Example usage for java.sql CallableStatement toString

List of usage examples for java.sql CallableStatement toString

Introduction

In this page you can find the example usage for java.sql CallableStatement toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.cws.esolutions.security.dao.userauth.impl.SQLAuthenticator.java

/**
 * @see com.cws.esolutions.security.dao.userauth.interfaces.Authenticator#verifySecurityData(java.lang.String, java.lang.String, java.util.List)
 *//*from  ww  w .  j a  v a  2  s.  co  m*/
public synchronized boolean verifySecurityData(final String userId, final String userGuid,
        final List<String> attributes) throws AuthenticatorException {
    final String methodName = SQLAuthenticator.CNAME
            + "#verifySecurityData(final String userId, final String userGuid, final List<String> attributes) throws AuthenticatorException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", userId);
        DEBUGGER.debug("Value: {}", userGuid);
    }

    Connection sqlConn = null;
    CallableStatement stmt = null;

    try {
        sqlConn = SQLAuthenticator.dataSource.getConnection();

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain application datasource connection");
        }

        sqlConn.setAutoCommit(true);

        stmt = sqlConn.prepareCall("{CALL verifySecurityQuestions(?, ?, ?, ?)}");
        stmt.setString(1, userGuid); // guid
        stmt.setString(2, userId);
        stmt.setString(3, attributes.get(0)); // username
        stmt.setString(4, attributes.get(1)); // username

        if (DEBUG) {
            DEBUGGER.debug("Statement: {}", stmt.toString());
        }

        return stmt.execute();
    } catch (SQLException sqx) {
        throw new AuthenticatorException(sqx.getMessage(), sqx);
    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }

            if (!(sqlConn == null) && (!(sqlConn.isClosed()))) {
                sqlConn.close();
            }
        } catch (SQLException sqx) {
            throw new AuthenticatorException(sqx.getMessage(), sqx);
        }
    }
}

From source file:org.castor.cpa.persistence.sql.keygen.SequenceDuringKeyGenerator.java

/**
 * {@inheritDoc}/* www . ja va  2  s  .  c  o  m*/
 */
public Object executeStatement(final Database database, final CastorConnection conn, final Identity identity,
        final ProposedEntity entity) throws PersistenceException {
    CastorStatement stmt = conn.createStatement();
    CallableStatement cstmt = null;
    try {
        SQLColumnInfo[] ids = _engine.getColumnInfoForIdentities();
        stmt.prepareStatement(_insert);
        String statement = stmt.toString();

        statement += " RETURNING ";
        statement += _factory.quoteName(ids[0].getName());
        statement += " INTO ?";
        statement = "{call " + statement + "}";

        stmt.setStatement(conn.getConnection().prepareCall(statement));

        if (LOG.isTraceEnabled()) {
            LOG.trace(Messages.format("jdo.creating", _engineType, stmt.toString()));
        }

        bindFields(entity, stmt);

        if (LOG.isTraceEnabled()) {
            LOG.trace(Messages.format("jdo.creating", _engineType, stmt.toString()));
        }

        // generate key during INSERT.
        cstmt = (CallableStatement) stmt.getStatement();

        int sqlType = ids[0].getSqlType();
        cstmt.registerOutParameter(stmt.getParameterSize() + 1, sqlType);

        if (LOG.isDebugEnabled()) {
            LOG.debug(Messages.format("jdo.creating", _engineType, cstmt.toString()));
        }

        cstmt.execute();

        // first skip all results "for maximum portability"
        // as proposed in CallableStatement javadocs.
        while (cstmt.getMoreResults() || (cstmt.getUpdateCount() != -1)) {
            // no code to execute
        }

        // identity is returned in the last parameter.
        // workaround for INTEGER type in Oracle getObject returns BigDecimal.
        Object temp;
        if (sqlType == java.sql.Types.INTEGER) {
            temp = new Integer(cstmt.getInt(stmt.getParameterSize() + 1));
        } else {
            temp = cstmt.getObject(stmt.getParameterSize() + 1);
        }
        return new Identity(ids[0].toJava(temp));
    } catch (SQLException except) {
        LOG.fatal(Messages.format("jdo.storeFatal", _engineType, stmt.toString()), except);
        throw new PersistenceException(Messages.format("persist.nested", except), except);
    } finally {
        //close statement
        try {
            if (cstmt != null) {
                cstmt.close();
            }
        } catch (SQLException e) {
            LOG.warn("Problem closing JDBC statement", e);
        }
        try {
            stmt.close();
        } catch (SQLException e) {
            LOG.warn("Problem closing JDBC statement", e);
        }
    }
}