List of usage examples for java.sql PreparedStatement setInt
void setInt(int parameterIndex, int x) throws SQLException;
int
value. From source file:net.mms_projects.copy_it.api.http.pages.v1.ClipboardUpdate.java
public FullHttpResponse onPostRequest(final HttpRequest request, final HttpPostRequestDecoder postRequestDecoder, final Database database, final HeaderVerifier headerVerifier) throws Exception { if (!headerVerifier.getConsumerScope().canWrite() || !headerVerifier.getUserScope().canWrite()) throw new ErrorException(NO_WRITE_PERMISSION); final InterfaceHttpData data = postRequestDecoder.getBodyHttpData("data"); if (data == null) throw new ErrorException(MISSING_DATA_PARAMETER); if (data instanceof HttpData) { PreparedStatement statement = database.getConnection().prepareStatement(INSERT_DATA); statement.setInt(1, headerVerifier.getUserId()); statement.setString(2, ((HttpData) data).getString()); statement.execute();// w ww. ja v a 2 s .c o m } else throw new ErrorException(MISSING_DATA_PARAMETER); dispatchNotification(database, headerVerifier.getUserId()); final JSONObject json = new JSONObject(); return new DefaultFullHttpResponse(request.getProtocolVersion(), OK, Unpooled.copiedBuffer(json.toString(), CharsetUtil.UTF_8)); }
From source file:net.mms_projects.copy_it.api.http.pages.android.UnRegisterGCM.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(); System.err.println(gcm_id); if (gcm_id.length() < 256) { 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//from w ww. ja va 2 s. c o m throw new ErrorException(GCM_TOKEN_TOO_LONG); } else throw new ErrorException(MISSING_GCM_TOKEN); }
From source file:com.wso2telco.gsma.authenticators.DBUtils.java
public static void insertPinAttempt(String msisdn, int attempts, String sessionId) throws SQLException, AuthenticatorException { Connection connection = null; PreparedStatement ps = null; String sql = "insert into multiplepasswords(username, attempts, ussdsessionid) values (?,?,?);"; connection = getConnectDBConnection(); ps = connection.prepareStatement(sql); ps.setString(1, msisdn);//from w w w.j a va 2s . c o m ps.setInt(2, attempts); ps.setString(3, sessionId); log.info(ps.toString()); ps.execute(); if (connection != null) { connection.close(); } }
From source file:lineage2.gameserver.model.entity.Hero.java
/** * Method deleteHero.//w ww. j ava 2s . c om * @param player Player */ public static void deleteHero(Player player) { Connection con = null; PreparedStatement statement = null; try { con = DatabaseFactory.getInstance().getConnection(); statement = con .prepareStatement("REPLACE INTO heroes (char_id, count, played, active) VALUES (?,?,?,?)"); for (Integer heroId : _heroes.keySet()) { int id = player.getObjectId(); if ((id > 0) && (heroId != id)) { continue; } StatsSet hero = _heroes.get(heroId); statement.setInt(1, heroId); statement.setInt(2, hero.getInteger(COUNT)); statement.setInt(3, hero.getInteger(PLAYED)); statement.setInt(4, 0); statement.execute(); if ((_completeHeroes != null) && !_completeHeroes.containsKey(heroId)) { _completeHeroes.remove(heroId); } } } catch (SQLException e) { _log.warn("Hero System: Couldnt update Heroes"); _log.error("", e); } finally { DbUtils.closeQuietly(con, statement); } }
From source file:mercury.DigitalMediaDAO.java
public final Integer uploadToDigitalMedia(FileItem file) { Connection con = null;/* w w w . jav a2 s.c o m*/ Integer serial = 0; String filename = file.getName(); if (filename.lastIndexOf('\\') != -1) { filename = filename.substring(filename.lastIndexOf('\\') + 1); } if (filename.lastIndexOf('/') != -1) { filename = filename.substring(filename.lastIndexOf('/') + 1); } try { InputStream is = file.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); serial = getNextSerial("digital_media_id_seq"); if (serial != 0) { con = getDataSource().getConnection(); con.setAutoCommit(false); String sql = " INSERT INTO digital_media " + " (id, file, mime_type, file_name) " + " VALUES (?, ?, ?, ?) "; PreparedStatement pstm = con.prepareStatement(sql); pstm.setInt(1, serial); pstm.setBinaryStream(2, bis, (int) file.getSize()); pstm.setString(3, file.getContentType()); pstm.setString(4, filename); pstm.executeUpdate(); pstm.close(); is.close(); con.commit(); } } catch (Exception e) { log.error(e.getMessage(), e); throw new DAOException(e.getMessage()); } finally { closeConnection(con); } return serial; }
From source file:dao.MaterialDaoImplem.java
@Override public boolean deleteMaterial(Material material) { try (Connection connection = dataSource.getConnection()) { String query = ("delete from material where id_material=?"); PreparedStatement stat = connection.prepareStatement(query); stat.setInt(1, material.getId_material()); stat.execute();/*from w ww . j av a2s . co m*/ return true; } catch (Exception e) { throw new RuntimeException("Error:deleteMaterial", e); } }
From source file:FlavorListServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); response.setContentType("text/html"); // Get the bounds of the ranks to be listed // or use defaults int lowLimit = getLimit(request.getParameter("lowLimit"), 0); int highLimit = getLimit(request.getParameter("highLimit"), 100); Connection con = null;/*from w w w. j av a2 s . c o m*/ try { // Connect to the ice cream database Class.forName(JDBC_DRIVER); con = DriverManager.getConnection(URL); // Run a query to get the top flavors String sql = "SELECT RANK, NAME" + " FROM flavors" + " WHERE RANK BETWEEN ? AND ?" + " ORDER BY RANK"; PreparedStatement pstmt = con.prepareStatement(sql); pstmt.setInt(1, lowLimit); pstmt.setInt(2, highLimit); ResultSet rs = pstmt.executeQuery(); // Print as an ordered list out.println("<ol>"); while (rs.next()) { int rank = rs.getInt(1); String name = rs.getString(2); out.println(" <li>" + name + "</li>"); } out.println("</ol>"); } catch (SQLException e) { throw new ServletException(e.getMessage()); } catch (ClassNotFoundException e) { throw new ServletException(e.getMessage()); } // Close the database finally { if (con != null) { try { con.close(); } catch (SQLException ignore) { } } } }
From source file:cn.vlabs.duckling.vwb.service.init.provider.PolicyInitProvider.java
private void saveSitePolicy(final SitePolicy sitePolicy) { if (sitePolicy == null) return;/*from w w w . j a va2 s .co m*/ getJdbcTemplate().update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection conn) throws SQLException { int i = 0; PreparedStatement ps = conn.prepareStatement(createSitePolicySQL); ps.setInt(++i, sitePolicy.getSiteId()); ps.setString(++i, sitePolicy.getPolicy()); return ps; } }); }
From source file:mx.com.pixup.portal.dao.MunicipioGenerateDaoJdbc.java
public void generateXML(int idMunicipioPasado) { //querys//from w w w . j a va 2s . c o m String sql = "SELECT * from municipio WHERE id = ?"; try { //seccion de preparacion de la query Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql); preparedStatement.setInt(1, idMunicipioPasado); ResultSet resultSet = preparedStatement.executeQuery(); //seccion de nodo raiz resultSet.next(); /*while (resultSet.next()) { //aqu se hace la magia para el XML }*/ Element municipio = new Element("municipio"); Attribute id = new Attribute("id", Integer.toString(resultSet.getInt("id"))); this.xmlLogico.setRootElement(municipio); municipio.setAttribute(id); //Elementos de 2do nivel Element nombre = new Element("nombre"); nombre.setText(resultSet.getString("nombre")); Element id_estado = new Element("id_estado"); id_estado.setText(Integer.toString(resultSet.getInt("id_estado"))); municipio.addContent(nombre); municipio.addContent(id_estado); //se genera el xml fsico this.xmlFisico.setFormat(Format.getRawFormat()); this.xmlFisico.output(this.xmlLogico, this.archivoFisico); } catch (Exception e) { //*** se quit el return porque el mtodo es void System.out.println(e.getMessage()); } }
From source file:cn.vlabs.duckling.vwb.service.init.provider.PolicyInitProvider.java
public void updateSitePolicy(final SitePolicy sitePolicy) { getJdbcTemplate().update(updateSitePolicy, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { int i = 0; ps.setInt(++i, sitePolicy.getSiteId()); ps.setString(++i, sitePolicy.getPolicy()); ps.setInt(++i, sitePolicy.getId()); }/*from w ww .j a v a 2 s .c o m*/ }); }