List of usage examples for java.sql PreparedStatement setInt
void setInt(int parameterIndex, int x) throws SQLException;
int
value. From source file:eagle.storage.jdbc.criteria.TestTorque.java
public void testSelect() throws TorqueException, SQLException { Criteria crit = new Criteria(); crit.setDbName("eagle"); crit.addSelectColumn(new ColumnImpl("column1")); crit.addSelectColumn(new ColumnImpl("column2")); crit.addSelectColumn(new ColumnImpl("column2/100")); crit.where(new ColumnImpl("column1"), SqlEnum.GREATER_EQUAL); crit.addFrom("tableName"); crit.addAlias("column1", "c1"); crit.addGroupByColumn(new ColumnImpl("column1")); crit.addAscendingOrderByColumn(new ColumnImpl("column3")); crit.setLimit(1000);//from www . ja v a 2s. c o m Query query = SqlBuilder.buildQuery(crit); String sql = query.toString(); System.out.println(sql); Connection connection = Torque.getConnection(); PreparedStatement statement = connection.prepareStatement(sql); statement.setInt(1, 1000); try { ResultSet result = statement.executeQuery(); } catch (SQLException ex) { LOG.warn(ex.getMessage(), ex); } finally { connection.close(); } }
From source file:net.sf.l2j.gameserver.model.entity.L2JOneoRusEvents.DM.java
public static void saveData() { java.sql.Connection con = null; try {//from w w w . j av a 2 s . c om con = L2DatabaseFactory.getInstance().getConnection(); 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.getMessage()); } finally { try { con.close(); } catch (Exception e) { } } }
From source file:dao.MaterialDaoImplem.java
@Override public Material selectMaterial(int id_material) { try (Connection connection = dataSource.getConnection()) { String query = ("select * from material m WHERE m.id_material=?"); PreparedStatement stat = connection.prepareStatement(query); stat.setInt(1, id_material); ResultSet res = stat.executeQuery(); if (res.next()) { Material material = new Material(); material.setId_material(res.getInt(1)); material.setName(res.getString(2)); material.setWeight(res.getInt(3)); material.setManufacturer(res.getString(4)); material.setCost(res.getInt(5)); material.setQuantity(res.getInt(6)); return material; } else {//from w w w.ja v a2 s. c o m return null; } } catch (Exception e) { throw new RuntimeException("Error:selectMaterial", e); } }
From source file:com.l2jfree.gameserver.instancemanager.BlockListManager.java
public synchronized void insert(L2Player listOwner, L2Player blocked) { Connection con = null;//from w w w .j a v a 2s . c o m try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement(INSERT_QUERY); statement.setInt(1, listOwner.getObjectId()); statement.setString(2, blocked.getName()); statement.execute(); statement.close(); } catch (SQLException e) { _log.warn("", e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.l2jfree.gameserver.instancemanager.BlockListManager.java
public synchronized void remove(L2Player listOwner, String name) { Connection con = null;/*from ww w . j a va2 s. c om*/ try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement(DELETE_QUERY); statement.setInt(1, listOwner.getObjectId()); statement.setString(2, name); statement.execute(); statement.close(); } catch (SQLException e) { _log.warn("", e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.dangdang.ddframe.rdb.sharding.example.config.spring.masterslave.repository.OrderRepositoryImpl.java
@Override public void insert() { String orderSql = "INSERT INTO `t_order` (`order_id`, `user_id`, `status`) VALUES (?, ?, ?)"; String orderItemSql = "INSERT INTO `t_order_item` (`order_item_id`, `order_id`, `user_id`, `status`) VALUES (?, ?, ?, ?)"; for (int orderId = 1; orderId <= 4; orderId++) { for (int userId = 1; userId <= 2; userId++) { try (Connection connection = shardingDataSource.getConnection()) { PreparedStatement preparedStatement = connection.prepareStatement(orderSql); preparedStatement.setInt(1, orderId); preparedStatement.setInt(2, userId); preparedStatement.setString(3, "insert"); preparedStatement.execute(); preparedStatement.close(); preparedStatement = connection.prepareStatement(orderItemSql); int orderItemId = orderId + 4; preparedStatement.setInt(1, orderItemId); preparedStatement.setInt(2, orderId); preparedStatement.setInt(3, userId); preparedStatement.setString(4, "insert"); preparedStatement.execute(); preparedStatement.close(); // CHECKSTYLE:OFF } catch (final Exception ex) { // CHECKSTYLE:ON ex.printStackTrace();//from ww w .j av a 2 s . c om } } } }
From source file:com.wwpass.cas.example.JdbcUserServiceDao.java
public void addRole(final int uid, String[] roles) { for (final String role : roles) { getJdbcTemplate().update(new PreparedStatementCreator() { @Override//w w w . j a va 2 s . c o m public PreparedStatement createPreparedStatement(Connection con) throws SQLException { PreparedStatement ps = con.prepareStatement(ADD_ROLE); ps.setInt(1, uid); ps.setString(2, role); return ps; } }); } }
From source file:br.com.fatecpg.repositories.mysql.MySqlLogRepository.java
@Override public Log getById(int id) { if (id <= 0) { throw new IllegalArgumentException("id must be greather than 0."); }/*from w w w . j a va 2 s . co m*/ Log log = null; String sql = "select id, applicationName, message, url, ipaddress, usernamme, createdon, details from log where id = ?"; Connection connection = dbProvider.getConnection(); try { PreparedStatement preparedStatement = connection.prepareStatement(sql); preparedStatement.setInt(1, id); ResultSet resultSet = preparedStatement.executeQuery(); if (resultSet.next()) { log = new Log(); log.setId(resultSet.getInt("id")); log.setApplicationName(resultSet.getString("applicationName")); log.setMessage(resultSet.getString("message")); log.setUrl(resultSet.getString("url")); log.setIpAddress("ipaddress"); log.setUsername(resultSet.getString("username")); log.setCreatedDate(resultSet.getDate("createdOn")); log.setDetails(resultSet.getString("details")); } } catch (SQLException ex) { throw new RuntimeException(ex); } return log; }
From source file:cai.flow.packets.V8_FlowAS.java
void fill_specific(PreparedStatement add_raw_stm) throws SQLException { add_raw_stm.setInt(13, (int) src_as); add_raw_stm.setInt(14, (int) dst_as); add_raw_stm.setInt(15, (int) input); add_raw_stm.setInt(16, (int) output); add_raw_stm.setString(17, Params.getCurrentTime()); }
From source file:net.mms_projects.copy_it.api.http.pages.android.RegisterGCM.java
public FullHttpResponse onPostRequest(final HttpRequest request, final HttpPostRequestDecoder postRequestDecoder, final Database database, final HeaderVerifier headerVerifier) throws Exception { if ((headerVerifier.getConsumerFlags() & Consumer.Flags.GCM) != Consumer.Flags.GCM) throw new ErrorException(YOU_SHOULD_NOT_USE_THIS); InterfaceHttpData gcm_token = postRequestDecoder.getBodyHttpData(GCM_TOKEN); if (gcm_token != null && gcm_token instanceof HttpData) { final String gcm_id = ((HttpData) gcm_token).getString(); if (gcm_id.length() < 256) { GCMRunnable gcmRunnable = new GCMRunnable(); gcmRunnable.addRegistrationId(gcm_id); gcmRunnable.setDryRun();//from w w w . j a va2s .com JSONObject output = gcmRunnable.send(); if (output.optInt(SUCCESS, 0) == 1) { PreparedStatement statement = database.getConnection().prepareStatement(INSERT_STATEMENT); statement.setInt(1, headerVerifier.getUserId()); statement.setString(2, gcm_id); if (statement.executeUpdate() > 0) database.getConnection().commit(); JSONObject json = new JSONObject(); return new DefaultFullHttpResponse(request.getProtocolVersion(), OK, Unpooled.copiedBuffer(json.toString(), CharsetUtil.UTF_8)); } else { String error = output.getJSONArray(RESULTS).getJSONObject(0).getString(ERROR); throw new ErrorException(error); } } else throw new ErrorException(GCM_TOKEN_TOO_LONG); } else throw new ErrorException(MISSING_GCM_TOKEN); }