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:dao.UpdateGlobalQuotaQuery.java
/** * This method is not called by spring./*ww w . j a v a2 s .c om*/ * * @param conn the connection passed to this. * @param entryid the entryid * @param quotaSize the quotaSize * @exception BaseDaoException */ public void run(Connection conn, String[] params) throws BaseDaoException { String entryid = params[0]; String quotaSize = params[1]; if (RegexStrUtil.isNull(entryid) || RegexStrUtil.isNull(quotaSize)) { throw new BaseDaoException("UpdateGlobalQuotaQuery, params[] memberId or QuotaSize is null"); } PreparedStatement query = null; String stmt = null; try { stmt = "update gquotas set qsize=" + quotaSize + " where entryid=" + entryid; query = conn.prepareStatement(stmt); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured, executing UpdateGlobalQuotaQuery, query = " + stmt, e); } }
From source file:dao.UpdateQuotaQuery.java
/** * This method is not called by spring.// ww w . j a va2 s .co m * * @param conn the connection passed to this. * @param memberid the memberid * @param quotaSize the quotaSize * @exception BaseDaoException */ public void run(Connection conn, String[] params) throws BaseDaoException { String memberid = params[0]; String quotaSize = params[1]; if (RegexStrUtil.isNull(memberid) || RegexStrUtil.isNull(quotaSize)) { throw new BaseDaoException("UpdateQuotaQuery, params[] memberId or QuotaSize is null"); } PreparedStatement query = null; String stmt = null; try { stmt = "update quotas set qsize=" + quotaSize + " where loginid=" + memberid; query = conn.prepareStatement(stmt); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured, executing UpdateQuotaQuery, query = " + stmt, e); } }
From source file:io.dstream.sql.BaseSqlTests.java
@Before public void before() throws Exception { System.out.println("Preparing DB"); String driver = "org.apache.derby.jdbc.EmbeddedDriver"; Class.forName(driver);// ww w . j av a 2 s . c om Connection c = DriverManager.getConnection(this.url); try { c.prepareStatement("DROP TABLE EMPLOYEE").executeUpdate(); } catch (Exception e) { // ignore } PreparedStatement create = c.prepareStatement("CREATE TABLE EMPLOYEE (" + "EMP_ID INT NOT NULL, " + "HIRE_DATE DATE NOT NULL, " + "EMP_NAME VARCHAR(20) NOT NULL, PRIMARY KEY (EMP_ID))"); create.executeUpdate(); c.prepareStatement( "INSERT INTO EMPLOYEE (EMP_ID, HIRE_DATE, EMP_NAME) VALUES (0, DATE('1994-02-23'), 'John Doe')") .executeUpdate(); c.prepareStatement( "INSERT INTO EMPLOYEE (EMP_ID, HIRE_DATE, EMP_NAME) VALUES (1, DATE('2013-05-03'), 'Steve Smith')") .executeUpdate(); c.prepareStatement( "INSERT INTO EMPLOYEE (EMP_ID, HIRE_DATE, EMP_NAME) VALUES (2, DATE('2013-02-13'), 'Steve Rogers')") .executeUpdate(); c.prepareStatement( "INSERT INTO EMPLOYEE (EMP_ID, HIRE_DATE, EMP_NAME) VALUES (3, DATE('2000-03-26'), 'Stacy Rodriguez')") .executeUpdate(); c.prepareStatement( "INSERT INTO EMPLOYEE (EMP_ID, HIRE_DATE, EMP_NAME) VALUES (4, DATE('2001-01-30'), 'Camila Wilson')") .executeUpdate(); }
From source file:com.uiip.gviviani.esercizioweekend.interfaces.impl.DefaultPersonDAO.java
@Override public boolean aggiornaPersonInfo(String numero, String data) { MysqlDataSource datasource = new MysqlDataSource(); datasource.setUser("root"); datasource.setPassword("root"); datasource.setUrl("jdbc:mysql://localhost:3306/Rubrica"); Connection connection = null; try {//from w w w. ja v a 2s. c o m connection = datasource.getConnection(); String sql = "UPDATE contatti SET data_nascita = ?" + "WHERE numero = ? ;"; PreparedStatement stat = connection.prepareStatement(sql); stat.setString(1, data); stat.setString(2, numero); if (stat.executeUpdate() > 0) { return true; } } catch (SQLException e) { logger.error(e); } finally { DbUtils.closeQuietly(connection); } return false; }
From source file:dao.DirHitsQuery.java
/** * This method is not called by spring./*from w w w. ja v a 2 s . c o m*/ * This method is used by DirectoryDao in incrementHits() method. * @param conn the connection passed to this. * @param directoryid the directoryid * @exception BaseDaoException */ public void run(Connection conn, String directoryid) throws BaseDaoException { PreparedStatement query = null; String stmt = null; try { stmt = "update low_priority directory set hits=hits+1 where directoryid=" + directoryid + " limit 1"; query = conn.prepareStatement(stmt); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured, executing directory updating hits, query = " + stmt, e); } }
From source file:com.gdo.project.util.SqlUtils.java
@Deprecated public static void preparedUpdate(PreparedStatement stmt) throws SQLException { try {//from ww w . ja v a2s . co m stmt.executeUpdate(); } finally { /**/ } }
From source file:com.softberries.klerk.dao.DocumentItemDao.java
public void delete(Long id, Connection conn) throws SQLException { PreparedStatement st = conn.prepareStatement(SQL_DELETE_DOCUMENTITEM); st.setLong(1, id);//from ww w .j ava 2 s . c o m // run the query int i = st.executeUpdate(); System.out.println("i: " + i); if (i == -1) { System.out.println("db error : " + SQL_DELETE_DOCUMENTITEM); } }
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 .com 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:dao.ContactDeleteShareMemberQuery.java
public void run(Connection conn, String ownerid, String memberid) throws BaseDaoException { PreparedStatement query = null; String stmt = "delete LOW_PRIORITY from membercontacts where ownerid=" + ownerid + " and memberid=" + memberid + " limit 1"; try {/* www. ja v a2 s . c o m*/ query = conn.prepareStatement(stmt); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing membercontacts deletequery" + stmt, e); } }
From source file:EditProductModel.EditProductWS.java
/** * Web service operation// w ww. j a v a 2s . c o m */ @WebMethod(operationName = "editProduct") public int editProduct(@WebParam(name = "access_token") String access_token, @WebParam(name = "product_id") String product_id, @WebParam(name = "product_name") String product_name, @WebParam(name = "description") String description, @WebParam(name = "price") String price, @WebParam(name = "img_name") String img_name, @WebParam(name = "img_byte") byte[] img_byte) throws ProtocolException, IOException, ParseException { int status = 0; Connection dbConn = DbConnectionManager.getConnection(); java.util.Date date = new java.util.Date(); java.sql.Date dateadded = new java.sql.Date(date.getTime()); java.sql.Time timeadded = new java.sql.Time(date.getTime()); int purchases = 0; 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"); switch (statusResp) { case "valid": try { String image_path = uploadImage(img_byte, img_name); String query = "UPDATE catalogue " + "SET productname= '" + product_name + "'" + ",price = '" + price + "'" + ",productdesc = '" + description + "'" + ",imagepath = '" + image_path + "'" + "WHERE product_id ='" + product_id + "'"; PreparedStatement ps = dbConn.prepareStatement(query); int i = ps.executeUpdate(); } catch (SQLException ex) { System.out.println("Inser to database failed: An Exception has occurred! " + ex); } finally { if (dbConn != null) { try { dbConn.close(); } catch (SQLException e) { System.out.println(e); } dbConn = null; } } status = 1; break; case "non-valid": status = 2; break; default: status = 3; break; } return status; }