Example usage for java.sql PreparedStatement clearParameters

List of usage examples for java.sql PreparedStatement clearParameters

Introduction

In this page you can find the example usage for java.sql PreparedStatement clearParameters.

Prototype

void clearParameters() throws SQLException;

Source Link

Document

Clears the current parameter values immediately.

Usage

From source file:com.pactera.edg.am.metamanager.extractor.dao.helper.DeleteDependencyHelper.java

private void doInPreparedStatement(long sysTime, MMDDependency dependency, PreparedStatement ps)
        throws SQLException {
    // ?ID/*from   w w  w .  jav  a2 s  .  c om*/
    ps.setString(1, dependency.getOwnerMetadata().getId());
    // ?ID
    ps.setString(2, dependency.getValueMetadata().getId());

    ps.addBatch();
    ps.clearParameters();

    if (++super.count % super.batchSize == 0) {
        ps.executeBatch();
        ps.clearBatch();
    }
}

From source file:com.adaptris.core.services.jdbc.JdbcIteratingDataCaptureServiceImpl.java

@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
    log.trace("Beginning doService in {}", LoggingHelper.friendlyName(this));
    Connection conn = null;/*from  ww  w . j  a  va  2s .c o m*/
    NamespaceContext namespaceCtx = SimpleNamespaceContext.create(getNamespaceContext(), msg);
    try {
        DocumentBuilderFactoryBuilder builder = documentFactoryBuilder();
        XPath xpath = XPath.newXPathInstance(builder, namespaceCtx);
        conn = configureActor(msg).getSqlConnection();
        Document doc = createDocument(namespaceCtx, msg);
        NodeList nodes = nodesToProcess(doc, xpath);
        log.debug("Iterating {} times for statement [{}]", nodes.getLength(), getStatement());
        PreparedStatement insert = actor.getInsertStatement(msg);
        insert.clearParameters();
        long rowsUpdated = 0;
        for (int i = 0; i < nodes.getLength(); i++) {
            log.trace("---Start Iteration {}", i);
            Node n = nodes.item(i);
            getParameterApplicator().applyStatementParameters(msg, insert, createActualParams(xpath, n),
                    getStatement());
            rowsUpdated += executeUpdate(insert);
            log.trace("---End Iteration {}", i);

        }
        rowsUpdated += finishUpdate(insert);
        // Will only store the generated keys from the last query
        saveKeys(msg, insert);
        commit(conn, msg);
        updateMetadata(msg, rowsUpdated);
    } catch (Exception e) {
        rollback(conn, msg);
        throw ExceptionHelper.wrapServiceException(e);
    } finally {
        JdbcUtil.closeQuietly(conn);
    }
}

From source file:nl.nn.adapterframework.jdbc.SimpleJdbcListener.java

protected void execute(Connection conn, String query, String parameter) throws ListenerException {
    if (StringUtils.isNotEmpty(query)) {
        if (trace && log.isDebugEnabled())
            log.debug("executing statement [" + query + "]");
        PreparedStatement stmt = null;
        try {//from  www .  j av a 2  s.c  o m
            stmt = conn.prepareStatement(query);
            stmt.clearParameters();
            if (StringUtils.isNotEmpty(parameter)) {
                log.debug("setting parameter 1 to [" + parameter + "]");
                stmt.setString(1, parameter);
            }
            stmt.execute();

        } catch (SQLException e) {
            throw new ListenerException(getLogPrefix() + "exception executing statement [" + query + "]", e);
        } finally {
            if (stmt != null) {
                try {
                    // log.debug("closing statement for ["+query+"]");
                    stmt.close();
                } catch (SQLException e) {
                    log.warn(getLogPrefix() + "exception closing statement [" + query + "]", e);
                }
            }
        }
    }
}

From source file:nl.nn.adapterframework.util.Locker.java

public void unlock(String objectIdWithSuffix) throws JdbcException, SQLException {
    if (LOCK_IGNORED.equals(objectIdWithSuffix)) {
        log.info("lock not set, ignoring unlock");
    } else {/*  w  w  w  . j a  v a  2  s .  c o m*/
        if (getType().equalsIgnoreCase("T")) {
            log.debug("preparing to remove lock [" + objectIdWithSuffix + "]");

            Connection conn;
            conn = getConnection();
            try {
                PreparedStatement stmt = conn.prepareStatement(deleteQuery);
                stmt.clearParameters();
                stmt.setString(1, objectIdWithSuffix);
                stmt.executeUpdate();
                log.debug("lock [" + objectIdWithSuffix + "] removed");
            } finally {
                try {
                    conn.close();
                } catch (SQLException e) {
                    log.error("error closing JdbcConnection", e);
                }
            }
        }
    }
}

From source file:org.jasig.portal.services.entityproperties.RDBMPropertyStore.java

public void unStoreProperty(EntityIdentifier entityID, String name) {
    Connection conn = null;/*  w w  w. j a v  a 2 s .  c o m*/
    PreparedStatement ps = null;
    try {
        conn = this.getConnection();
        ps = conn.prepareStatement(deleteProperty);
        try {
            ps.clearParameters();
            ps.setInt(1, org.jasig.portal.EntityTypes.getEntityTypeID(entityID.getType()).intValue());
            ps.setString(2, entityID.getKey());
            ps.setString(3, name);
            ps.executeUpdate();
        } finally {
            close(ps);
        }
        clearCache(entityID);
    } catch (Exception e) {
        log.error("RDBMPropertyStore.unStoreProperty " + ps, e);
    } finally {
        this.releaseConnection(conn);
    }
}

From source file:org.jasig.portal.services.entityproperties.RDBMPropertyStore.java

public void storeProperty(EntityIdentifier entityID, String name, String value) {
    this.unStoreProperty(entityID, name);
    Connection conn = null;//from w  w  w  .j  av a2 s .  co m
    PreparedStatement ps = null;
    try {
        conn = this.getConnection();
        ps = conn.prepareStatement(insertProperty);
        try {
            ps.clearParameters();
            ps.setInt(1, org.jasig.portal.EntityTypes.getEntityTypeID(entityID.getType()).intValue());
            ps.setString(2, entityID.getKey());
            ps.setString(3, name);
            ps.setString(4, value);
            ps.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
            ps.executeUpdate();
        } finally {
            close(ps);
        }
        clearCache(entityID);
    } catch (Exception e) {
        log.error("RDBMPropertyStore.storeProperty " + ps, e);
    } finally {
        this.releaseConnection(conn);
    }
}

From source file:org.sakaiproject.search.component.dao.impl.SearchBuilderItemDaoImpl.java

private int countPending(Connection connection) {

    PreparedStatement pst = null;
    ResultSet rst = null;/*from   www .j ava  2s .c  om*/
    try {
        pst = connection.prepareStatement("select count(*) from searchbuilderitem where searchstate = ? ");
        pst.clearParameters();
        pst.setInt(1, SearchBuilderItem.STATE_PENDING.intValue());
        rst = pst.executeQuery();
        if (rst.next()) {
            return rst.getInt(1);
        }
        return 0;
    } catch (SQLException sqlex) {
        return 0;
    } finally {
        try {
            rst.close();
        } catch (Exception ex) {
            dlog.warn("Exception counting pending items", ex);
        }
        try {
            pst.close();
        } catch (Exception ex) {
            dlog.warn("Exception counting pending items", ex);
        }
    }

}

From source file:org.accada.epcis.repository.query.QueryOperationsSession.java

/**
 * Lazy instantiation of prepared statements: the PreparedStatement is
 * created when it is first used by the application and is then cached here.
 * //from w w w  .j a  va 2s .  c om
 * @param sql
 * @return
 * @throws SQLException
 */
public PreparedStatement getPreparedStatement(final String sql) throws SQLException {
    PreparedStatement ps = namedStatements.get(sql);
    if (ps == null) {
        ps = connection.prepareStatement(sql);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Prepared SQL statement: " + sql);
        }
        namedStatements.put(sql, ps);
    }
    ps.clearParameters();
    return ps;
}

From source file:co.marcin.novaguilds.impl.storage.AbstractDatabaseStorage.java

/**
 * Gets a prepared statement//w w w.  j  a  v  a 2s .  c o m
 *
 * @param statement the enum
 * @return the statement
 * @throws SQLException
 */
public PreparedStatement getPreparedStatement(PreparedStatements statement) throws SQLException {
    if (preparedStatementMap.isEmpty() || !preparedStatementMap.containsKey(statement)) {
        prepareStatements();
    }

    if (preparedStatementMap.get(statement) != null && !(this instanceof SQLiteStorageImpl)
            && preparedStatementMap.get(statement).isClosed()) {
        prepareStatements();
    }

    PreparedStatement preparedStatement = preparedStatementMap.get(statement);
    preparedStatement.clearParameters();

    return preparedStatement;
}

From source file:org.jasig.portal.services.entityproperties.RDBMPropertyStore.java

protected EntityProperties getCachedProperties(EntityIdentifier entityID) {
    EntityProperties ep = EntityPropertyRegistry.instance().getCachedProperties(entityID);
    if (ep == null) {
        ep = new EntityProperties(entityID.getKey());
        Connection conn = null;/* w  w  w . j  av a  2s.c o  m*/
        PreparedStatement ps = null;
        try {
            conn = this.getConnection();
            ps = conn.prepareStatement(selectProperties);
            try {
                ps.clearParameters();
                ps.setInt(1, org.jasig.portal.EntityTypes.getEntityTypeID(entityID.getType()).intValue());
                ps.setString(2, entityID.getKey());
                ResultSet rs = ps.executeQuery();
                try {
                    while (rs.next()) {
                        ep.setProperty(rs.getString(NAME_COL), rs.getString(VALUE_COL));
                    }
                    addToCache(ep);
                } finally {
                    close(rs);
                }
            } finally {
                close(ps);
            }
        } catch (Exception e) {
            log.error("RDBMPropertyStore.getCachedProperties: " + ps, e);
        } finally {
            this.releaseConnection(conn);
        }
    }
    return ep;
}