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:com.artivisi.iso8583.persistence.MapperServiceTestIT.java

private void verifyMapper(Mapper m, Connection conn, String name, String description) throws SQLException {
    String sqlSelectMapper = "select * from iso8583_mapper where id = ?";
    PreparedStatement psSelectMapper = conn.prepareStatement(sqlSelectMapper);
    psSelectMapper.setString(1, m.getId());
    ResultSet rsSelectMapper = psSelectMapper.executeQuery();
    assertTrue(rsSelectMapper.next());//from   ww w .j  a va2  s. co  m
    assertEquals(name, rsSelectMapper.getString("name"));
    assertEquals(description, rsSelectMapper.getString("description"));
}

From source file:at.alladin.rmbt.db.dao.TestStatDao.java

@Override
public int save(TestStat result) throws SQLException {
    final String sql = "INSERT INTO test_stat (test_uid, cpu_usage, mem_usage) VALUES (?,?::json,?::json)";
    final PreparedStatement ps = conn.prepareStatement(sql);
    ps.setLong(1, result.getTestUid());// w ww . j a va 2 s  . c o  m
    ps.setString(2, result.getCpuUsage().toString());
    ps.setString(3, result.getMemUsage().toString());
    return ps.executeUpdate();
}

From source file:net.duckling.ddl.service.param.dao.ParamDAOImpl.java

@Override
public void create(final Param param) {
    getJdbcTemplate().update(INSERT_PARAM, new PreparedStatementSetter() {
        @Override//  w w w  . j  av a2  s .c o m
        public void setValues(PreparedStatement ps) throws SQLException {
            int i = 0;
            ps.setString(++i, param.getItemId());
            ps.setString(++i, param.getKey());
            ps.setString(++i, param.getValue());
            ps.setString(++i, param.getType());

        }
    });
}

From source file:com.javacreed.examples.spring.ExampleDao.java

public long addNew(final String name) {
    final PreparedStatementCreator psc = new PreparedStatementCreator() {
        @Override/*from w  w  w .j  av  a 2 s .  co  m*/
        public PreparedStatement createPreparedStatement(final Connection connection) throws SQLException {
            final PreparedStatement ps = connection.prepareStatement("INSERT INTO `names` (`name`) VALUES (?)",
                    Statement.RETURN_GENERATED_KEYS);
            ps.setString(1, name);
            return ps;
        }
    };

    // The newly generated key will be saved in this object
    final KeyHolder holder = new GeneratedKeyHolder();

    jdbcTemplate.update(psc, holder);

    final long newNameId = holder.getKey().longValue();
    return newNameId;
}

From source file:com.uiip.gviviani.esercizioweekend.interfaces.impl.DefaultPersonDAO.java

@Override
public PersonModel getPersonInfo(String numero) {
    PersonModel personModel = new PersonModel();
    PhoneModel phone = new PhoneModel();
    MysqlDataSource datasource = new MysqlDataSource();
    datasource.setUser("root");
    datasource.setPassword("root");
    datasource.setUrl("jdbc:mysql://localhost:3306/Rubrica");
    Connection connection = null;
    try {//from  www .  j  a v a2s .  c om
        connection = datasource.getConnection();
        String sql = "SELECT c.nome, c.cognome, c.data_nascita, t.name "
                + "FROM contatti c INNER JOIN telefono t ON (c.modello = t.id)" + "WHERE c.numero = ? ;";
        PreparedStatement stat = connection.prepareStatement(sql);
        stat.setString(1, numero);
        ResultSet res = stat.executeQuery();
        if (res.first()) {
            personModel.setNome(res.getString("nome"));
            personModel.setCognome(res.getString("cognome"));
            personModel.setData(res.getString("data_nascita"));
            personModel.setNumero(numero);
            phone.setNome(res.getString("name"));
            personModel.setModel(phone);
        } else {
            personModel = null;
        }
    } catch (SQLException e) {
        logger.error(e);
        personModel = null;
    } finally {
        DbUtils.closeQuietly(connection);
    }
    return personModel;
}

From source file:io.muic.ooc.webapp.service.UserService.java

public boolean userExist(Connection conn, String id) {

    if (id == null) {
        return false;
    }//w w  w  . j av a  2s.c o m

    String query = "SELECT * from account WHERE id = ?";
    try {
        PreparedStatement preparedStatement = conn.prepareStatement(query);
        preparedStatement.setString(1, id);

        // do update
        ResultSet resultSet = preparedStatement.executeQuery();

        while (resultSet.next()) {
            System.out.println("User Exist function");
            if (resultSet.getString("id").equals(id)) {
                return true;
            }
        }
        return false;
    } catch (SQLException e) {
        System.out.println("Can't check");
    }
    return false;
}

From source file:net.duckling.ddl.service.param.dao.ParamDAOImpl.java

@Override
public void update(final Param param) {
    getJdbcTemplate().update(UPDATE_PARAM, new PreparedStatementSetter() {
        @Override/*w  w  w .java 2 s  .c om*/
        public void setValues(PreparedStatement ps) throws SQLException {
            int i = 0;
            ps.setString(++i, param.getItemId());
            ps.setString(++i, param.getKey());
            ps.setString(++i, param.getValue());
            ps.setString(++i, param.getType());
            ps.setInt(++i, param.getId());

        }
    });

}

From source file:edu.cmu.lti.oaqa.openqa.hello.eval.passage.PassageMAPEvalPersistenceProvider.java

@Override
public void insertMAPMeasureEval(final Key key, final String eName, final PassageMAPEvaluationData eval)
        throws SQLException {
    String insert = getInsertMAPMeasureEval();
    final Trace trace = key.getTrace();
    DataStoreImpl.getInstance().jdbcTemplate().update(insert, new PreparedStatementSetter() {
        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setString(1, key.getExperiment());
            ps.setString(2, trace.getTrace());
            ps.setString(3, eName);//from w  w  w. j  a va 2  s  .c om
            ps.setFloat(4, eval.getDocMap());
            ps.setFloat(5, eval.getPsgMap());
            ps.setFloat(6, eval.getAspMap());
            ps.setFloat(7, eval.getCount());
            ps.setInt(8, key.getStage());
            ps.setString(9, trace.getTraceHash());
        }
    });
}

From source file:com.uit.anonymousidentity.Repository.Nonces.NonceJDBCTemplate.java

@Override
public boolean isFresh(Nonce n) throws SQLException {
    String sql = "select * from " + TABLE_NAME + " where " + SID + " = ? and " + VALUE + " = ?";
    PreparedStatement pst = dataSource.getConnection().prepareStatement(sql);
    pst.setString(1, n.getIssuerSid());
    pst.setBytes(2, n.getByteArray());/*from  w w w.j  a v  a2  s .  co m*/

    ResultSet rs = pst.executeQuery();
    if (rs.next()) {
        return false;
    } else
        return true;

}

From source file:com.wwpass.cas.example.JdbcUserServiceDao.java

public void createWwpass(final String puid, final int uid) {
    if (createWwpassAssociationQuery == null) {
        createWwpassAssociationQuery = CREATE_WWPASS_ASSOCIATION;
    }//from w  w  w .ja va 2s  .  co  m
    getJdbcTemplate().update(new PreparedStatementCreator() {
        @Override
        public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
            PreparedStatement ps = con.prepareStatement(createWwpassAssociationQuery);
            ps.setString(1, puid);
            ps.setInt(2, uid);
            return ps;
        }
    });
}