List of usage examples for java.sql PreparedStatement setInt
void setInt(int parameterIndex, int x) throws SQLException;
int
value. From source file:br.inpe.XSDMiner.MineXSD.java
@Override public void process(SCMRepository repo, Commit commit, PersistenceMechanism writer) { String projectName = ""; String fullName = ""; try {//from ww w. jav a2s .co m if (!commit.getBranches().contains("master")) return; if (commit.isMerge()) return; Class.forName("org.postgresql.Driver"); projectName = repo.getPath().substring(repo.getPath().lastIndexOf("/") + 1); for (Modification m : commit.getModifications()) { String fName = m.getFileName(); String addrem = ""; String fullNameNew = m.getNewPath(); String fullNameOld = m.getOldPath(); if (fullNameNew.equals("/dev/null")) { addrem = "r"; fullName = fullNameOld; } else { fullName = fullNameNew; } if (fullNameOld.equals("/dev/null")) { addrem = "a"; } String fileExtension = fName.substring(fName.lastIndexOf(".") + 1); boolean isWSDL = fileExtension.equals("wsdl"); boolean isXSD = fileExtension.equals("xsd"); if (!(isWSDL || isXSD)) continue; InputStream input = new ByteArrayInputStream(m.getSourceCode().getBytes(StandardCharsets.UTF_8)); ByteArrayOutputStream outputXSD = new ByteArrayOutputStream(); String[] schemas; if (fileExtension.equals("wsdl")) { XSDExtractor.wsdlToXSD(input, outputXSD); schemas = XSDExtractor.splitXSD(outputXSD.toString()); } else { outputXSD.write(IOUtils.toString(input).getBytes()); schemas = new String[1]; schemas[0] = outputXSD.toString(); } String url = "jdbc:postgresql://localhost/xsdminer"; Properties props = new Properties(); props.setProperty("user", "postgres"); props.setProperty("password", "070910"); Connection conn = DriverManager.getConnection(url, props); int schemaCount = schemas.length; for (int i = 0; i < schemaCount; i++) { String query = "INSERT INTO files VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; PreparedStatement st = conn.prepareStatement(query); st.setInt(1, i + 1); st.setString(2, fullName); st.setString(3, projectName); st.setString(4, commit.getHash()); st.setTimestamp(5, new java.sql.Timestamp(commit.getDate().getTimeInMillis())); st.setString(6, schemas[i]); st.setString(7, addrem); st.setBoolean(8, false); st.executeUpdate(); st.close(); } conn.close(); } } catch (IOException ex) { Logger.getLogger(MineXSD.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block System.out.println("Failure - Project " + projectName + "; file: " + fullName); //e.printStackTrace(); } finally { repo.getScm().reset(); } }
From source file:com.assignment4.products.Pro_details.java
@GET @Path("{id}") @Produces(MediaType.APPLICATION_JSON)// w w w . j a v a 2s.co m public String getproduct(@PathParam("id") int id) throws SQLException { if (conn == null) { return "not connected"; } else { String q = "Select * from products where product_id = ?"; PreparedStatement ps = conn.prepareStatement(q); ps.setInt(1, id); ResultSet rs = ps.executeQuery(); String result = ""; JSONArray proArr = new JSONArray(); while (rs.next()) { Map pm = new LinkedHashMap(); pm.put("productID", rs.getInt("product_id")); pm.put("name", rs.getString("name")); pm.put("description", rs.getString("description")); pm.put("quantity", rs.getInt("quantity")); proArr.add(pm); } result = proArr.toString(); return result; } }
From source file:net.freechoice.model.orm.Map_Transaction.java
@Override public PreparedStatementCreator createInsert(final FC_Transaction transaction) { return new PreparedStatementCreator() { @Override/*ww w. j a v a2s.c o m*/ public PreparedStatement createPreparedStatement(Connection con) throws SQLException { PreparedStatement ps = con.prepareStatement( "insert into FC_Transaction(" + "id_account_, " + "amount, comment)" + " values(?, ?, ?)", RET_ID); ps.setInt(1, transaction.id_account_); ps.setBigDecimal(2, transaction.amount); ps.setString(3, transaction.comment); return ps; } }; }
From source file:com.concursive.connect.web.modules.badges.dao.BadgeLogoFile.java
public boolean insert(Connection db) throws SQLException { boolean result = false; // The required linkModuleId linkModuleId = Constants.BADGE_FILES; // Determine if the database is in auto-commit mode boolean doCommit = false; try {/*from www .j a v a2 s . c o m*/ if (doCommit = db.getAutoCommit()) { db.setAutoCommit(false); } // Insert the record result = super.insert(db); // Update the referenced pointer if (result) { int i = 0; PreparedStatement pst = db .prepareStatement("UPDATE badge " + "SET logo_id = ? " + "WHERE badge_id = ? "); pst.setInt(++i, id); pst.setInt(++i, linkItemId); int count = pst.executeUpdate(); result = (count == 1); } if (doCommit) { db.commit(); } } catch (Exception e) { if (doCommit) { db.rollback(); } throw new SQLException(e.getMessage()); } finally { if (doCommit) { db.setAutoCommit(true); } } return result; }
From source file:com.oracle.products.ProductResource.java
@DELETE @Path("{id}") @Consumes(MediaType.APPLICATION_JSON)/* w w w .ja va 2s.co m*/ @Produces(MediaType.TEXT_PLAIN) public String deleteProduct(@PathParam("id") int id) throws SQLException { if (conn == null) { return "not connected"; } else { String query = "DELETE FROM product WHERE product_id = ?"; PreparedStatement pstmt = conn.prepareStatement(query); pstmt.setInt(1, id); pstmt.executeUpdate(); return "The specified row is deleted"; } }
From source file:net.freechoice.model.orm.Map_Comment.java
@Override public PreparedStatementCreator createInsert(final FC_Comment comment) { return new PreparedStatementCreator() { @Override//from ww w. ja v a 2 s.c o m public PreparedStatement createPreparedStatement(Connection con) throws SQLException { PreparedStatement ps = con.prepareStatement( "insert into FC_Comment(" + "id_post_, email, name, comment)" + " values(?, ?, ?, ?)", RET_ID); ps.setInt(1, comment.id_post_); ps.setString(2, comment.email); ps.setString(3, comment.name); ps.setString(4, comment.comment); return ps; } }; }
From source file:com.imagelake.control.KeyWordsDAOImp.java
@Override public boolean getKeyWords(String keyword, int images_images_id) { boolean ok = false; try {//from w ww .j a v a 2s . co m String sql = "SELECT * FROM key_words WHERE key_word=? AND images_images_id=?"; Connection con = DBFactory.getConnection(); PreparedStatement ps = con.prepareStatement(sql); ps.setString(1, keyword); ps.setInt(2, images_images_id); ResultSet rs = ps.executeQuery(); if (rs.next()) { ok = false; } else { ok = true; } } catch (Exception e) { e.printStackTrace(); } return ok; }
From source file:com.imagelake.control.KeyWordsDAOImp.java
@Override public boolean addKeyWords(int images_images_id, String keyword) { System.out.println("Add key words:" + images_images_id); boolean ok = false; try {/* w ww . ja va2 s . co m*/ String sql = "INSERT INTO key_words(key_word,images_images_id)VALUES(?,?)"; Connection con = DBFactory.getConnection(); PreparedStatement ps = con.prepareStatement(sql); ps.setString(1, keyword); ps.setInt(2, images_images_id); int i = ps.executeUpdate(); if (i > 0) { ok = true; } else { ok = false; } } catch (Exception e) { e.printStackTrace(); } System.out.println("addKeyWords:" + ok); return ok; }
From source file:com.product.Product.java
@DELETE @Path("{id}") @Consumes(MediaType.TEXT_PLAIN)// ww w.j a v a2 s . com @Produces(MediaType.TEXT_PLAIN) public String deleteProduct(@PathParam("id") int id) throws SQLException { if (connect == null) { return "not connected"; } else { String query = "DELETE FROM product WHERE product_id = ?"; PreparedStatement prepstmnt = connect.prepareStatement(query); prepstmnt.setInt(1, id); prepstmnt.executeUpdate(); return "The specified row is deleted"; } }
From source file:com.l2jfree.gameserver.model.entity.hellbound.TowerOfNaiaRoom.java
public void initDoors(final int roomId) { Connection con = null;/* w ww .j av a 2s .c o m*/ try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement("SELECT * FROM hb_naia_doorlist WHERE room_id=?"); statement.setInt(1, roomId); ResultSet rset = statement.executeQuery(); while (rset.next()) { int doorId = rset.getInt("door_id"); byte action = rset.getByte("action_order"); switch (action) { case 0: _preOpenDoorIds = ArrayUtils.add(_preOpenDoorIds, doorId); break; case 1: _preCloseDoorIds = ArrayUtils.add(_preOpenDoorIds, doorId); break; case 2: _postOpenDoorIds = ArrayUtils.add(_preOpenDoorIds, doorId); break; case 3: _postCloseDoorIds = ArrayUtils.add(_preOpenDoorIds, doorId); break; } } rset.close(); statement.close(); } catch (Exception e) { _log.warn("TowerOfNaia: Door could not be initialized: ", e); } finally { L2DatabaseFactory.close(con); } }