List of usage examples for java.sql PreparedStatement setString
void setString(int parameterIndex, String x) throws SQLException;
String
value. From source file:com.mycompany.rubricatelefonica.DefaultSmartphoneDao.java
public SmartphoneModel getSmartphoneInfo(String imei) { SmartphoneModel smartphoneModel = new SmartphoneModel(); MysqlDataSource dataSource = new MysqlDataSource(); dataSource.setUser("root"); dataSource.setPassword("root"); dataSource.setUrl("jdbc:mysql://localhost:3306/RubricaTelef"); Connection conn = null;// w w w .j a v a2 s .c o m try { conn = dataSource.getConnection(); PreparedStatement stmtUserInfo = conn.prepareStatement(SMARTPHONE_INFO); stmtUserInfo.setString(1, imei); ResultSet rsUserInfoSet = stmtUserInfo.executeQuery(); if (rsUserInfoSet.first()) { smartphoneModel = new SmartphoneModel(); smartphoneModel.setMarca(rsUserInfoSet.getString("marca")); smartphoneModel.setModello(rsUserInfoSet.getString("modello")); smartphoneModel.setColore(rsUserInfoSet.getString("colore")); smartphoneModel.setMateriale(rsUserInfoSet.getString("materiale")); } } catch (SQLException e) { System.out.println(e.getMessage()); System.out.println("errore!!"); } finally { DbUtils.closeQuietly(conn); //oppure try with resource } return smartphoneModel; }
From source file:edu.cmu.lti.oaqa.openqa.hello.eval.passage.PassageMAPEvalPersistenceProvider.java
@Override public void deletePassageMeasureEval(final ExperimentKey experiment) { String insert = getDeletePassageMeasureEval(); DataStoreImpl.getInstance().jdbcTemplate().update(insert, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, experiment.getExperiment()); ps.setInt(2, experiment.getStage()); }//ww w . j av a2 s . c o m }); }
From source file:com.clican.pluto.orm.usertype.StringSplitType.java
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException { if (value == null) { st.setString(index, ""); } else if (value instanceof String[]) { StringBuffer result = new StringBuffer(); for (String s : ((String[]) value)) { result.append(s);// w w w . j av a 2 s .c o m result.append(","); } if (result.length() == 0) { st.setString(index, ""); } else { st.setString(index, result.toString().substring(0, result.length() - 1)); } } else { throw new HibernateException("The property must be a comma-split string."); } }
From source file:com.mycompany.rubricatelefonica.DefaultSmartphoneDao.java
public boolean insertNewSmartphone(SmartphoneModel s) { boolean inserito = false; MysqlDataSource dataSource = new MysqlDataSource(); dataSource.setUser("root"); dataSource.setPassword("root"); dataSource.setUrl("jdbc:mysql://localhost:3306/RubricaTelef"); Connection conn = null;//from www . j a v a 2 s . c o m try { conn = dataSource.getConnection(); PreparedStatement stmtInsertSmartph = conn.prepareStatement(INSERT_SMARTPHONE); stmtInsertSmartph.setString(1, s.getImei()); stmtInsertSmartph.setString(2, s.getMarca()); stmtInsertSmartph.setString(3, s.getModello()); stmtInsertSmartph.setString(4, s.getAnno()); stmtInsertSmartph.setString(5, s.getColore()); stmtInsertSmartph.setString(6, s.getMateriale()); stmtInsertSmartph.setString(7, s.getSistOp()); if (stmtInsertSmartph.executeUpdate() > 0) { inserito = true; } } catch (SQLException e) { System.out.println(e.getMessage()); System.out.println("errore!! Connessione Fallita"); } finally { DbUtils.closeQuietly(conn); //oppure try with resource } return inserito; }
From source file:hr.fer.zemris.vhdllab.dao.impl.AbstractEntityDaoTest.java
private void setupNamedEntity(final String name) { String query = createInsertStatement("NamedEntityTable", "id, version, name", "null, 0, ?"); getJdbcTemplate().execute(query, new PreparedStatementCallback() { @Override/*w ww . j a v a 2s. c om*/ public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException { ps.setString(1, name); return ps.execute(); } }); }
From source file:edu.cmu.lti.oaqa.openqa.hello.eval.passage.PassageMAPEvalPersistenceProvider.java
@Override public void deletePassageAggrEval(final Key key, final String sequenceId) { final String name = getClass().getSimpleName(); String insert = getDeletePassageAggrEval(); DataStoreImpl.getInstance().jdbcTemplate().update(insert, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, key.getExperiment()); ps.setString(2, key.getTrace().getTraceHash()); ps.setString(3, name);/* www .j a va 2s . c o m*/ ps.setString(4, sequenceId); } }); }
From source file:de.bley.word.filewriter.WriterJdbc.java
/** * * Schreibt einen Datensatz in eine Tabelle. * * @param col//from w w w . j av a 2s .c o m * @param text * @param flag * */ @Override public void writeInFile(final String col, final String text, final boolean flag) { Connection connection = JdbcConnection.getInstance().connect(); if (connection != null) { try { PreparedStatement ps = connection.prepareStatement("INSERT INTO APP.MYTABLE (DATA) VALUES (?)"); ps.setString(1, text); ps.executeUpdate(); connection.close(); } catch (SQLException ex) { log.debug("execute of Query (write in file)", ex); } } }
From source file:UpdateMySqlClobServlet.java
public void updateCLOB(Connection conn, String id, String fileContent) throws Exception { PreparedStatement pstmt = null; try {//from w w w .ja va 2s. co m pstmt = conn.prepareStatement("update dataTable set filebody= ? where id = ?"); pstmt.setString(1, fileContent); pstmt.setString(2, id); pstmt.executeUpdate(); } finally { pstmt.close(); } }
From source file:com.artivisi.iso8583.persistence.MapperServiceTestIT.java
private void verifyCountMapper(Mapper m, Connection conn, int count) throws SQLException { String sqlSelectMapper = "select count(*) from iso8583_mapper where name = ?"; PreparedStatement psSelectMapper = conn.prepareStatement(sqlSelectMapper); psSelectMapper.setString(1, m.getName()); ResultSet rsSelectMapper = psSelectMapper.executeQuery(); assertTrue(rsSelectMapper.next());/* w w w.j ava 2s. co m*/ assertEquals(new Integer(count), new Integer(rsSelectMapper.getInt(1))); }
From source file:edu.umd.cs.marmoset.modelClasses.CodeMetrics.java
private int putValues(PreparedStatement stmt, int index) throws SQLException { stmt.setInt(index++, getTestRunPK()); stmt.setString(index++, getMd5sumSourcefiles()); stmt.setString(index++, getMd5sumClassfiles()); stmt.setInt(index++, getCodeSegmentSize()); return index; }