Example usage for java.sql PreparedStatement setString

List of usage examples for java.sql PreparedStatement setString

Introduction

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

Prototype

void setString(int parameterIndex, String x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given Java String value.

Usage

From source file:io.kamax.mxisd.backend.sql.SynapseSqlDirectoryProvider.java

@Override
protected void setParameters(PreparedStatement stmt, String searchTerm) throws SQLException {
    stmt.setString(1, "%" + searchTerm + "%");
}

From source file:com.taobao.tddl.common.sync.RowBasedReplicationExecutor.java

/**
 * jdbcupdate//from  ww  w .  ja v a 2s  .  c o  m
 */
public static void batchUpdateSyncLog(Collection<RowBasedReplicationContext> contexts,
        final long extraPlusTime) {
    long timeused, time0 = System.currentTimeMillis();
    String sqlpattern = "update sync_log_{0} set next_sync_time=? where id = ?";

    /**
     * RowBasedReplicationContextupdateSql
     */
    Map<JdbcTemplate, Map<String/*logSQL*/, List<RowBasedReplicationContext>>> sortedContexts = buildSortedContexts(
            contexts, sqlpattern.toString());

    for (Map.Entry<JdbcTemplate, Map<String, List<RowBasedReplicationContext>>> e0 : sortedContexts
            .entrySet()) {
        JdbcTemplate jt = e0.getKey();
        for (Map.Entry<String, List<RowBasedReplicationContext>> e : e0.getValue().entrySet()) {
            final List<RowBasedReplicationContext> endContexts = e.getValue();
            BatchPreparedStatementSetter setter = new BatchPreparedStatementSetter() {
                public int getBatchSize() {
                    return endContexts.size();
                }

                public void setValues(PreparedStatement ps, int i) throws SQLException {
                    RowBasedReplicationContext context = endContexts.get(i);
                    ps.setTimestamp(1, getNextSyncTime(context, extraPlusTime));
                    ps.setString(2, context.getSyncLogId());
                }
            };
            jt.batchUpdate(e.getKey(), setter);
            if (log.isDebugEnabled()) {
                log.debug("[batchUpdateSyncLog], sql = [" + e.getKey() + "], batch size=" + endContexts.size());
            }
        }
    }

    timeused = System.currentTimeMillis() - time0;
    log.warn(contexts.size() + " replication logs updated, time used:" + timeused);
    Monitor.add(Monitor.KEY1, Monitor.KEY2_SYNC, Monitor.KEY3_BatchUpdateSyncLog, contexts.size(), timeused);
}

From source file:edu.cmu.lti.oaqa.framework.log.impl.JdbcLogPersistenceProvider.java

@Override
public void log(final String uuid, final Trace trace, final LogEntry type, final String message) {
    System.out.printf("[logger] %s,%s,%s,%s,%s\n", new Date(), uuid, trace, type, message);
    String insert = (String) getParameterValue("insert-log-entry-query");
    DataStoreImpl.getInstance().jdbcTemplate().update(insert, new PreparedStatementSetter() {
        @Override/*from w w  w. j  a v  a  2 s  .co  m*/
        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setString(1, uuid);
            ps.setString(2, trace.getTraceHash());
            ps.setString(3, type.toString());
            ps.setString(4, message);
        }
    });
}

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

protected void setPs(PreparedStatement ps, int index) throws SQLException {
    // ID//from   w  ww  .  ja va 2s .  c  o  m
    ps.setString(index + 1, taskInstanceId);
    // 
    ps.setString(index + 2, "0");
    // ?:,
    ps.setString(index + 3, "2"); //2-
}

From source file:com.wso2telco.gsma.authenticators.DBUtils.java

public static void updateIdsRegStatus(String username, String status)
        throws SQLException, AuthenticatorException {
    Connection connection;/*from   ww  w  .  ja va2 s.  co m*/
    PreparedStatement ps;

    String sql = "update `regstatus` set " + "status=? where " + "username=?;";

    connection = getConnectDBConnection();

    ps = connection.prepareStatement(sql);

    ps.setString(1, status);
    ps.setString(2, username);
    log.info(ps.toString());
    ps.execute();

    if (connection != null) {
        connection.close();
    }
}

From source file:com.thoughtworks.go.server.dao.handlers.FileTypeHandlerCallback.java

@Override
public void setNonNullParameter(PreparedStatement ps, int i, File parameter, JdbcType jdbcType)
        throws SQLException {
    ps.setString(i, FilenameUtils.separatorsToUnix(parameter.getPath()));
}

From source file:com.aurel.track.dbase.MigrateTo37.java

private static void addLongTextFieldChange(PreparedStatement pstmtLongText, Integer fieldChangeID,
        Integer transactionID, String description) {
    try {//  w  w  w  .  j a v a  2  s.com
        pstmtLongText.setInt(1, fieldChangeID);
        pstmtLongText.setInt(2, TFieldChangeBean.COMPOUND_HISTORY_FIELD);
        pstmtLongText.setInt(3, transactionID);
        pstmtLongText.setString(4, description);
        pstmtLongText.setInt(5, ValueType.LONGTEXT);
        pstmtLongText.setString(6, UUID.randomUUID().toString());
        pstmtLongText.executeUpdate();
    } catch (SQLException e) {
        LOGGER.error("Adding a field change for long text with transactionID " + transactionID
                + " fieldChangeID " + fieldChangeID + " failed with " + e.getMessage(), e);
        System.err.println(ExceptionUtils.getStackTrace(e));
    }
}

From source file:com.wso2telco.gsma.authenticators.DBUtils.java

public static void updateAuthenticateData(String msisdn, String status)
        throws SQLException, AuthenticatorException {
    Connection connection = null;
    PreparedStatement ps = null;
    String sql = "update `authenticated_login` set " + "status=? where " + "msisdn=?;";

    connection = getConnectDBConnection();
    ps = connection.prepareStatement(sql);
    ps.setString(1, status);
    ps.setString(2, msisdn);/*from w  w  w  .  ja v a2s .com*/
    log.info(ps.toString());
    ps.execute();

    if (connection != null) {
        connection.close();
    }
}

From source file:com.apress.prospringintegration.springenterprise.stocks.dao.jdbc.PSStockCreater.java

public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
    String sql = "INSERT INTO " + "STOCKS (SYMBOL, INVENTORY_CODE, PRICE_PER_SHARE,"
            + "QUANTITY_AVAILABLE, EXCHANGE_ID, PURCHASE_DATE) " + "VALUES (?, ?, ?, ?, ?, ?)";
    PreparedStatement ps = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);

    ps.setString(1, stock.getSymbol());
    ps.setString(2, stock.getInventoryCode());
    ps.setFloat(3, stock.getSharePrice());
    ps.setFloat(4, stock.getQuantityAvailable());
    ps.setString(5, stock.getExchangeId());
    ps.setDate(6, new java.sql.Date(stock.getPurchaseDate().getTime()));
    return ps;//  ww w  . j  a v a 2 s  . c  o m
}

From source file:com.wso2telco.gsma.authenticators.DBUtils.java

public static String insertAuthFlowStatus(String username, String status, String uuid)
        throws SQLException, AuthenticatorException {

    Connection connection = null;
    PreparedStatement ps = null;
    String sql = "INSERT INTO `regstatus` (`uuid`,`username`, `status`) VALUES (?,?,?);";
    connection = getConnectDBConnection();
    ps = connection.prepareStatement(sql);
    ps.setString(1, uuid);
    ps.setString(2, username);/*w ww .j a  v a  2 s  .  c  om*/
    ps.setString(3, status);
    log.info(ps.toString());
    ps.execute();

    if (connection != null) {
        connection.close();
    }
    return uuid;
}