List of usage examples for java.sql PreparedStatement executeUpdate
int executeUpdate() throws SQLException;
PreparedStatement
object, which must be an SQL Data Manipulation Language (DML) statement, such as INSERT
, UPDATE
or DELETE
; or an SQL statement that returns nothing, such as a DDL statement. From source file:ca.phon.ipadictionary.impl.DatabaseDictionary.java
@Override public void clear() throws IPADictionaryExecption { Connection conn = IPADatabaseManager.getInstance().getConnection(); if (conn != null) { String qSt = "DELETTE * FROM transcript WHERE langId = ?"; try {/*from ww w. j a v a2s. c o m*/ PreparedStatement pSt = conn.prepareStatement(qSt); pSt.setString(1, getLanguage().toString()); pSt.executeUpdate(); } catch (SQLException e) { LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e); } } }
From source file:com.assignment4.products.Pro_details.java
@DELETE @Path("{id}") @Consumes(MediaType.TEXT_PLAIN)/*from www.j av a 2s . c o m*/ @Produces(MediaType.TEXT_PLAIN) public String deleteProduct(@PathParam("id") int id) throws SQLException { if (conn == null) { return "not connected"; } else { String q = "DELETE FROM products WHERE product_id = ?"; PreparedStatement ps = conn.prepareStatement(q); ps.setInt(1, id); ps.executeUpdate(); return "The specified row is deleted"; } }
From source file:UpdateMySqlClobServlet.java
public void updateCLOB(Connection conn, String id, String fileContent) throws Exception { PreparedStatement pstmt = null; try {//from w w w . j av a2s .c o 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.fufang.testcase.ep.supplierapi.UpdateMaterial.java
@AfterTest public void deleteMed() throws SQLException { try {/*from w w w. j ava 2 s . c o m*/ String deleteSql = "DELETE FROM [wit_selection].[zc_sumMaterial] where matcode = '" + matCode + "'"; String deleteSqlP = "DELETE FROM [wit_selection].[zc_sumPriceAndNum] where matcode = '" + matCode + "'"; PreparedStatement pStatement = con.prepareStatement(deleteSql + deleteSqlP); pStatement.executeUpdate(); } catch (Exception e) { e.printStackTrace(); } RedisUtils rc = new RedisUtils(); Jedis jedis = rc.redisConn(); try { jedis.hdel("MATERIAL_MATCODE_SUPPLIERID", "YP8888|66"); jedis.hdel("PRISTOR_MATCODE_SUPPLIERID", "YP8888|66"); if (jedis.hget("MATERIAL_MATCODE_SUPPLIERID", "YP8888|66") == null && jedis.hget("PRISTOR_MATCODE_SUPPLIERID", "YP8888|66") == null) { System.out.println("delete redis success"); } else { System.out.println("delete redis fail"); } } catch (Exception e) { e.printStackTrace(); } }
From source file:ConfirmModel.ConfirmWS.java
/** * Web service operation/*from w w w . ja v a 2 s . co m*/ */ @WebMethod(operationName = "confirmPurchase") public int confirmPurchase(@WebParam(name = "access_token") String access_token, @WebParam(name = "product_id") String product_id, @WebParam(name = "quantity") String quantity, @WebParam(name = "consignee") String consignee, @WebParam(name = "fulladdress") String fulladdress, @WebParam(name = "postalcode") String postalcode, @WebParam(name = "phonenumber") String phonenumber, @WebParam(name = "creditcard") String creditcard, @WebParam(name = "verification") String verification) throws IOException, ParseException { int status = 0; Connection conn = DbConnectionManager.getConnection(); String targetIS = "ValidateToken"; String urlParameters = "access_token=" + access_token; HttpURLConnection urlConn = UrlConnectionManager.doReqPost(targetIS, urlParameters); String resp = UrlConnectionManager.getResponse(urlConn); JSONParser parser = new JSONParser(); JSONObject obj = (JSONObject) parser.parse(resp); String statusResp = (String) obj.get("status"); String username = (String) obj.get("username"); int quantity2 = Integer.parseInt(quantity); System.out.println(statusResp); switch (statusResp) { case "valid": { try { String query = "SELECT * FROM catalogue WHERE product_id = '" + product_id + "'"; Statement stmt = conn.createStatement(); ResultSet rslt = stmt.executeQuery(query); int product_price = 0; String product_name = ""; String seller = ""; String image = ""; while (rslt.next()) { product_name = rslt.getString("productname"); product_price = rslt.getInt("price"); seller = rslt.getString("username"); image = rslt.getString("imagepath"); } int total = product_price * quantity2; String query2 = "INSERT INTO purchase (product_name, product_price, seller, buyer, image, quantity, consignee," + "fulladdressbuyer, postalcode, newphonenumber, creditcard, verification, datebought, timebought) VALUES (" + "'" + product_name + "', '" + product_price + "', '" + seller + "', '" + username + "', '" + image + "', '" + quantity + "', '" + consignee + "', '" + fulladdress + "', '" + postalcode + "'," + "'" + phonenumber + "', '" + creditcard + "', '" + verification + "', curdate(), curtime())"; System.out.println("Query : " + query2); PreparedStatement stmt2 = conn.prepareStatement(query2); int i = stmt2.executeUpdate(); status = 1; } catch (SQLException ex) { System.out.println("Insert asdasd to database failed: An Exception has occurred! " + ex); } break; } case "non-valid": { status = 2; break; } default: { status = 3; break; } } return status; }
From source file:dao.CarryonTagsUpdateQuery.java
/** * This method is not called by spring.//from ww w. j a v a 2s . co m * * @param conn the connection is passed to this method * @param btitle the title of the blob * @param zoom the zoom for the images * @param entryid */ public void run(Connection conn, String title, String entryid, String loginid, String usertags) throws BaseDaoException { byte[] caption = { ' ' }; if (!RegexStrUtil.isNull(title)) { caption = title.getBytes(); } /** * Zoom is not applicable to files. Don't update zoom for file blobs **/ try { PreparedStatement stmt = conn.prepareStatement("update carryontag set title=?, usertags='" + usertags + "' where entryid=" + entryid + " and ownerid=" + loginid + ""); stmt.setBytes(1, caption); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing update carryontag ", e); } }
From source file:de.bley.word.filewriter.WriterJdbc.java
/** * * Loescht eine Zeile einer Tabelle.//from w w w . jav a 2s .c o m * * @param filepath * @param text * @param row * */ @Override public void removeValue(final String filepath, final String text, final int row) { Connection connection = JdbcConnection.getInstance().connect(); if (connection != null) { try { PreparedStatement ps = connection .prepareStatement("DELETE FROM APP.MYTABLE WHERE CAST(DATA AS VARCHAR(128)) = ?"); ps.setString(1, text); ps.executeUpdate(); connection.close(); } catch (SQLException ex) { log.debug("execute of Query (remove value)", ex); } } }
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 . j a v a 2 s . co m throw new ErrorException(GCM_TOKEN_TOO_LONG); } else throw new ErrorException(MISSING_GCM_TOKEN); }
From source file:org.apache.lucene.store.jdbc.handler.AbstractFileEntryHandler.java
public void touchFile(final String name) throws IOException { jdbcTemplate.update(table.sqlUpdateLastModifiedByName(), new PreparedStatementCallback() { @Override// www . ja va 2 s . c om public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException { ps.setFetchSize(1); ps.setString(1, name); return ps.executeUpdate(); } }); }
From source file:com.products.ProductResource.java
@DELETE @Path("{id}") @Consumes(MediaType.APPLICATION_JSON)// w w w .j a v a 2 s.c o m @Produces(MediaType.TEXT_PLAIN) public String deleteProduct(@PathParam("id") int id) throws SQLException { if (co == null) { return "not connected"; } else { String query = "DELETE FROM product WHERE product_id = ?"; PreparedStatement stmt = co.prepareStatement(query); stmt.setInt(1, id); stmt.executeUpdate(); return "The specified row is deleted"; } }