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:cn.cuizuoli.appranking.typehandler.CountryTypeHandler.java

@Override
public void setNonNullParameter(PreparedStatement ps, int i, Country parameter, JdbcType jdbcType)
        throws SQLException {
    ps.setString(i, parameter.getCode());
}

From source file:cn.cuizuoli.appranking.typehandler.FeedTypeTypeHandler.java

@Override
public void setNonNullParameter(PreparedStatement ps, int i, FeedType parameter, JdbcType jdbcType)
        throws SQLException {
    ps.setString(i, parameter.getCode());
}

From source file:org.apache.lucene.store.jdbc.handler.ActualDeleteFileEntryHandler.java

public void deleteFile(final String name) throws IOException {
    jdbcTemplate.execute(table.sqlDeleteByName(), new PreparedStatementCallback() {
        @Override/*from   w  w  w .  j a  va 2  s . c o m*/
        public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
            ps.setFetchSize(1);
            ps.setString(1, name);
            return ps.executeUpdate();
        }
    });
}

From source file:cn.cuizuoli.appranking.typehandler.MediaTypeTypeHandler.java

@Override
public void setNonNullParameter(PreparedStatement ps, int i, MediaType parameter, JdbcType jdbcType)
        throws SQLException {
    ps.setString(i, parameter.getCode());
}

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

public static void updateMultiplePasswordNoOfAttempts(String username, int attempts)
        throws SQLException, AuthenticatorException {

    Connection connection = null;
    PreparedStatement ps = null;

    String sql = "update `multiplepasswords` set  attempts=? where  username=?;";

    connection = getConnectDBConnection();

    ps = connection.prepareStatement(sql);

    ps.setInt(1, attempts);/* w  w w .j ava 2 s. co m*/
    ps.setString(2, username);
    log.info(ps.toString());
    ps.execute();

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

From source file:dk.netarkivet.common.utils.DBUtils.java

/**
 * Prepare a statement given a query string and some args.
 *
 * NB: the provided connection is not closed.
 *
 * @param c a Database connection/*from  w w w  . j a v  a  2 s . co m*/
 * @param query a query string  (must not be null or empty)
 * @param args some args to insert into this query string (must not be null)
 * @return a prepared statement
 * @throws SQLException If unable to prepare a statement
 * @throws ArgumentNotValid If unable to handle type of one the args, or
 * the arguments are either null or an empty String.
 */
public static PreparedStatement prepareStatement(Connection c, String query, Object... args)
        throws SQLException {
    ArgumentNotValid.checkNotNull(c, "Connection c");
    ArgumentNotValid.checkNotNullOrEmpty(query, "String query");
    ArgumentNotValid.checkNotNull(args, "Object... args");
    PreparedStatement s = c.prepareStatement(query);
    int i = 1;
    for (Object arg : args) {
        if (arg instanceof String) {
            s.setString(i, (String) arg);
        } else if (arg instanceof Integer) {
            s.setInt(i, (Integer) arg);
        } else if (arg instanceof Long) {
            s.setLong(i, (Long) arg);
        } else if (arg instanceof Boolean) {
            s.setBoolean(i, (Boolean) arg);
        } else if (arg instanceof Date) {
            s.setTimestamp(i, new Timestamp(((Date) arg).getTime()));
        } else {
            throw new ArgumentNotValid("Cannot handle type '" + arg.getClass().getName()
                    + "'. We can only handle string, " + "int, long, date or boolean args for query: " + query);
        }
        i++;
    }
    return s;
}

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

@Override
public void update(final Stock stock) {
    jdbcTemplate.update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
            String sql = "UPDATE STOCKS SET SYMBOL = ?, INVENTORY_CODE = ?, "
                    + "PRICE_PER_SHARE = ?, QUANTITY_AVAILABLE = ?, "
                    + "EXCHANGE_ID = ?, PURCHASE_DATE = ? where ID = ?";
            PreparedStatement ps = connection.prepareStatement(sql);
            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()));
            ps.setInt(7, stock.getId());
            return ps;
        }/*ww w  .  j a  v a  2s.co m*/
    });
}

From source file:com.ccoe.build.dal.PluginJDBCTemplate.java

public int create(final Plugin plugin) {
    final String SQL = "insert into RBT_PLUGIN (plugin_key, group_id, artifact_id, version, phase) values (?, ?, ?, ?, ?)";

    KeyHolder keyHolder = new GeneratedKeyHolder();
    jdbcTemplateObject.update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
            PreparedStatement ps = connection.prepareStatement(SQL, new String[] { "id" });
            ps.setString(1, plugin.getPluginKey());
            ps.setString(2, plugin.getGroupId());
            ps.setString(3, plugin.getArtifactId());
            ps.setString(4, plugin.getVersion());
            ps.setString(5, plugin.getPhaseName());

            return ps;
        }// w w w.j  ava2  s. c  o m
    }, keyHolder);

    return keyHolder.getKey().intValue();
}

From source file:cn.cuizuoli.appranking.typehandler.DeviceTypeTypeHandler.java

@Override
public void setNonNullParameter(PreparedStatement ps, int i, DeviceType parameter, JdbcType jdbcType)
        throws SQLException {
    ps.setString(i, parameter.getCode());

}

From source file:com.siemens.scr.avt.ad.hibernate.StringXMLType.java

public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
    st.setString(index, (String) value);
}