List of usage examples for java.sql PreparedStatement setInt
void setInt(int parameterIndex, int x) throws SQLException;
int
value. From source file:dao.MaterialDaoImplem.java
@Override public boolean updateMaterial(Material material) { try (Connection connection = dataSource.getConnection()) { String query = ("update Material m " + "set m.name=?, m.weight=?, m.manufacturer=?,m.cost=?,m.quantity=? WHERE m.id_material=?"); PreparedStatement stat = connection.prepareStatement(query); stat.setString(1, material.getName()); stat.setInt(2, material.getWeight()); stat.setString(3, material.getManufacturer()); stat.setInt(4, material.getCost()); stat.setInt(5, material.getQuantity()); stat.setInt(6, material.getId_material()); stat.execute();/*from w ww .j a va 2s . c om*/ return true; } catch (Exception e) { throw new RuntimeException("Error:updateMaterial", e); } }
From source file:net.sf.jdbcwrappers.trim.TrimmingTest.java
@Test public void testPreparedStatement() throws SQLException { PreparedStatement statement = connection.prepareStatement("SELECT * FROM TEST WHERE INT_COL=?"); try {//from www . ja va 2 s . co m statement.setInt(1, 12); ResultSet rs = statement.executeQuery(); rs.next(); assertEquals("test", rs.getString(2)); assertEquals("test", rs.getString("CHAR_COL")); } finally { statement.close(); } }
From source file:org.cbioportal.database.annotator.AnnotateRecordsWriter.java
private void deleteMutationEvent(MutationEvent event) throws Exception { PreparedStatement pstmt = con.prepareStatement("delete from mutation_event where mutation_event_id = ?"); pstmt.setInt(1, event.getMUTATION_EVENT_ID()); log.info("Deleting mutation event. Properly annotated event already exists in database: " + event.getMUTATION_EVENT_ID()); }
From source file:com.fpmislata.banco.persistencia.impl.MovimientoBancarioDAOImplJDBC.java
@Override public void delete(int id) { Connection connection = connectionFactory.getConnection(); String SQL = "DELETE FROM movimientobancario WHERE id= ?"; try {//from w ww. j a v a2 s.co m PreparedStatement preparedStatement = connection.prepareStatement(SQL); preparedStatement.setInt(1, id); preparedStatement.executeUpdate(); } catch (Exception ex) { throw new RuntimeException("Error al borrar", ex); } finally { try { connection.close(); } catch (SQLException ex) { throw new RuntimeException(ex); } } }
From source file:com.l2jfree.gameserver.model.entity.events.DM.java
public static void saveData() { Connection con = null;/*w w w. j ava 2s. co m*/ try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement; statement = con.prepareStatement("Delete from dm"); statement.execute(); statement.close(); statement = con.prepareStatement( "INSERT INTO dm (eventName, eventDesc, joiningLocation, minlvl, maxlvl, npcId, npcX, npcY, npcZ, rewardId, rewardAmount, color, playerX, playerY, playerZ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); statement.setString(1, _eventName); statement.setString(2, _eventDesc); statement.setString(3, _joiningLocationName); statement.setInt(4, _minlvl); statement.setInt(5, _maxlvl); statement.setInt(6, _npcId); statement.setInt(7, _npcX); statement.setInt(8, _npcY); statement.setInt(9, _npcZ); statement.setInt(10, _rewardId); statement.setInt(11, _rewardAmount); statement.setInt(12, _playerColors); statement.setInt(13, _playerX); statement.setInt(14, _playerY); statement.setInt(15, _playerZ); statement.execute(); statement.close(); } catch (Exception e) { _log.error("Exception: DM.saveData(): ", e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.manning.junitbook.ch14.ejbs.TestAdministratorEJB.java
/** * @see TestCase#setUp()/*from w ww . j a va 2 s . c o m*/ */ public void setUp() throws Exception { Properties properties = new Properties(); properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); properties.put("java.naming.factory.url.pkgs", "org.jboss.naming rg.jnp.interfaces"); InitialContext ctx = new InitialContext(properties); administrator = (IAdministratorLocal) ctx .lookup("ch14-cactus-ear-cactified/" + AdministratorBean.class.getSimpleName() + "/local"); Connection conn = getConnection(); Statement s = conn.createStatement(); s.execute("DROP TABLE USERS IF EXISTS"); s.execute("CREATE TABLE USERS(ID INT, NAME VARCHAR(40))"); PreparedStatement psInsert = conn.prepareStatement("INSERT INTO USERS VALUES (?, ?)"); psInsert.setInt(1, 1); psInsert.setString(2, "User 1"); psInsert.executeUpdate(); psInsert.setInt(1, 2); psInsert.setString(2, "User 2"); psInsert.executeUpdate(); }
From source file:net.freechoice.model.orm.Map_Tag.java
@Override public PreparedStatementCreator createUpdate(final FC_Tag entity) { return new PreparedStatementCreator() { @Override//from w w w . ja va 2 s . co m public PreparedStatement createPreparedStatement(Connection con) throws SQLException { PreparedStatement ps = con .prepareStatement("update FC_Tag" + " set content = ? " + "where id = ? "); ps.setString(1, entity.content); ps.setInt(2, entity.id); return ps; } }; }
From source file:com.fpmislata.banco.persistencia.impl.MovimientoBancarioDAOImplJDBC.java
@Override public MovimientoBancario update(MovimientoBancario movimientoBancario) { Connection connection = connectionFactory.getConnection(); String SQL = "UPDATE movimientobancario SET cuentapertenece =? , importe = ? , saldoTotal = ? , tipoMovimiento = ?, concepto = ? WHERE id = ?"; try {//from ww w . j a va 2 s .c om PreparedStatement preparedStatement = connection.prepareStatement(SQL); preparedStatement.setInt(1, movimientoBancario.getCuentaPertenece()); preparedStatement.setString(2, movimientoBancario.getImporte()); preparedStatement.setString(3, movimientoBancario.getSaldoTotal()); preparedStatement.setString(4, movimientoBancario.getTipoMovimiento()); preparedStatement.setString(5, movimientoBancario.getConcepto()); preparedStatement.setInt(6, movimientoBancario.getId()); preparedStatement.executeUpdate(); movimientoBancario.setFecha(new Date()); return get(movimientoBancario.getId()); } catch (Exception ex) { throw new RuntimeException("Error al actualizar la entidad", ex); } finally { try { connection.close(); } catch (SQLException ex) { throw new RuntimeException(ex); } } }
From source file:com.fpmislata.banco.persistencia.impl.SucursalBancariaDAOImplJDBC.java
@Override public void delete(int id) { Connection connection = connectionFactory.getConnection(); String SQL = "DELETE FROM sucursalbancaria WHERE id=?"; try {// w ww. j av a2 s . c om PreparedStatement preparedStatement = connection.prepareStatement(SQL); preparedStatement.setInt(1, id); preparedStatement.execute(); } catch (Exception ex) { throw new RuntimeException(ex); } finally { try { connection.close(); } catch (Exception ex) { throw new RuntimeException(ex); } } }
From source file:com.l2jfree.gameserver.instancemanager.FriendListManager.java
public synchronized Set<Integer> getFriendList(Integer objectId) { Set<Integer> set = _friends.get(objectId); if (set == null) { _friends.put(objectId, set = new LazyFastSet<Integer>()); Connection con = null;//from www . j a va2 s . co m try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement(SELECT_QUERY); statement.setInt(1, objectId); statement.setInt(2, objectId); ResultSet rset = statement.executeQuery(); while (rset.next()) { Integer objId1 = L2Integer.valueOf(rset.getInt("charId1")); Integer objId2 = L2Integer.valueOf(rset.getInt("charId2")); Set<Integer> set1 = _friends.get(objId1); if (set1 != null) set1.add(objId2); Set<Integer> set2 = _friends.get(objId2); if (set2 != null) set2.add(objId1); } rset.close(); statement.close(); } catch (SQLException e) { _log.warn("", e); } finally { L2DatabaseFactory.close(con); } } return set; }