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:com.spend.spendService.MainPage.java
private void createSearchQueue() { try {/*from w w w . j a v a 2 s . c o m*/ String st = getSearchQuery(); String[] selist = getSearchEngineNamesArray(); for (Object se : selist) { String SQLi = "INSERT INTO searchqueue (searchText,searchEngineName, disabled) VALUES (?,?,0)"; PreparedStatement pstmt = con2.prepareStatement(SQLi); pstmt.setString(1, st); pstmt.setString(2, se.toString()); pstmt.executeUpdate(); pstmt.close(); } } catch (Exception ex) { System.out.println(ex.getMessage()); } }
From source file:dao.DirAdminAddQuery.java
/** * This method is not called by spring.// w ww. j a v a2 s. co m * This method adds an admin into this directory * @param conn the connection passed to this. * @param dirid the directory id * @param ownerid the author id for this directory * @exception BaseDaoException */ public void run(Connection conn, String dirid, String ownerid) throws BaseDaoException { if (conn != null) { logger.info("conn != null + dirid =" + dirid + " ownerid = " + ownerid); } else { logger.info("conn is null"); } PreparedStatement query = null; String stmt = null; try { stmt = "insert into diradmin values (0, " + ownerid + ", " + dirid + ")"; logger.info("stmt = " + stmt); query = conn.prepareStatement(stmt); query.executeUpdate(); } catch (Exception e) { logger.info("e.getMessage() " + e.getMessage()); throw new BaseDaoException( "Error occured while executing diradmin addquery(), " + stmt + e.getMessage(), e); } }
From source file:dao.DirCobrandUpdateFooterQuery.java
/** * This method is not called by spring.//from ww w .ja v a 2s. c om * * @param conn the connection passed to this. * @param directoryid the directoryid * @param footer the footer * @exception BaseDaoException */ public void run(Connection conn, String directoryid, byte[] footer) throws BaseDaoException { PreparedStatement query = null; String stmt = null; try { stmt = "update dircobrand set footer=? where directoryid=" + directoryid + " limit 1"; query = conn.prepareStatement(stmt); query.setBytes(1, footer); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing dircobrand updating query, query = " + stmt, e); } }
From source file:dao.DirCobrandUpdateHeaderQuery.java
/** * This method is not called by spring.//from w w w.j av a 2 s. c o m * * @param conn the connection passed to this. * @param directoryid the directoryid * @param header the header * @exception BaseDaoException */ public void run(Connection conn, String directoryid, byte[] header) throws BaseDaoException { PreparedStatement query = null; String stmt = null; try { stmt = "update dircobrand set header=? where directoryid=" + directoryid + " limit 1"; query = conn.prepareStatement(stmt); query.setBytes(1, header); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing dircobrand updating query, query = " + stmt, e); } }
From source file:com.ywang.alone.handler.task.AuthTask.java
/** * { 'key':'2597aa1d37d432a','fid':'1020293' } * /*ww w . jav a 2 s.c o m*/ * @param param * @return */ private static String follow(String msg) { JSONObject jsonObject = AloneUtil.newRetJsonObject(); JSONObject param = JSON.parseObject(msg); String token = param.getString("key"); String userId = null; if (StringUtils.isEmpty(token)) { jsonObject.put("ret", Constant.RET.NO_ACCESS_AUTH); jsonObject.put("errCode", Constant.ErrorCode.NO_ACCESS_AUTH); jsonObject.put("errDesc", Constant.ErrorDesc.NO_ACCESS_AUTH); return jsonObject.toJSONString(); } Jedis jedis = JedisUtil.getJedis(); Long tokenTtl = jedis.ttl("TOKEN:" + token); if (tokenTtl == -1) { jsonObject.put("ret", Constant.RET.NO_ACCESS_AUTH); jsonObject.put("errCode", Constant.ErrorCode.NO_ACCESS_AUTH); jsonObject.put("errDesc", Constant.ErrorDesc.NO_ACCESS_AUTH); } else { userId = jedis.get("TOKEN:" + token); LoggerUtil.logMsg("uid is " + userId); } JedisUtil.returnJedis(jedis); if (StringUtils.isEmpty(userId)) { jsonObject.put("ret", Constant.RET.NO_ACCESS_AUTH); jsonObject.put("errCode", Constant.ErrorCode.NO_ACCESS_AUTH); jsonObject.put("errDesc", Constant.ErrorDesc.NO_ACCESS_AUTH); return jsonObject.toJSONString(); } DruidPooledConnection conn = null; PreparedStatement stmt = null; try { conn = DataSourceFactory.getInstance().getConn(); conn.setAutoCommit(false); stmt = conn.prepareStatement("insert into follow (USER_ID, FOLLOWED_ID, `TIME`) VALUES (?,?,?)", Statement.RETURN_GENERATED_KEYS); stmt.setString(1, userId); stmt.setString(2, param.getString("fid").trim()); stmt.setLong(3, System.currentTimeMillis()); int result = stmt.executeUpdate(); if (result != 1) { jsonObject.put("ret", Constant.RET.UPDATE_DB_FAIL); jsonObject.put("errCode", Constant.ErrorCode.UPDATE_DB_FAIL); jsonObject.put("errDesc", Constant.ErrorDesc.UPDATE_DB_FAIL); } conn.commit(); conn.setAutoCommit(true); } catch (SQLException e) { LoggerUtil.logServerErr(e); jsonObject.put("ret", Constant.RET.SYS_ERR); jsonObject.put("errCode", Constant.ErrorCode.SYS_ERR); jsonObject.put("errDesc", Constant.ErrorDesc.SYS_ERR); } finally { try { if (null != stmt) { stmt.close(); } if (null != conn) { conn.close(); } } catch (SQLException e) { LoggerUtil.logServerErr(e.getMessage()); } } return jsonObject.toJSONString(); }
From source file:dao.ColCobrandUpdateFooterQuery.java
/** * This method is not called by spring.//from w w w. j av a 2 s . co m * * @param conn the connection passed to this. * @param collabrumid the collabrumid * @param footer the footer * @exception BaseDaoException */ public void run(Connection conn, String collabrumid, byte[] footer) throws BaseDaoException { PreparedStatement query = null; String stmt = null; try { stmt = "update collcobrand set footer=? where collabrumid=" + collabrumid + " limit 1"; query = conn.prepareStatement(stmt); query.setBytes(1, footer); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing collcobrand updating query, query = " + stmt, e); } }
From source file:dao.ColCobrandUpdateHeaderQuery.java
/** * This method is not called by spring./*from w w w. jav a2s . c o m*/ * * @param conn the connection passed to this. * @param collabrumid the collabrumid * @param header the header * @exception BaseDaoException */ public void run(Connection conn, String collabrumid, byte[] header) throws BaseDaoException { PreparedStatement query = null; String stmt = null; try { stmt = "update collcobrand set header=? where collabrumid=" + collabrumid + " limit 1"; query = conn.prepareStatement(stmt); query.setBytes(1, header); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing collcobrand updating query, query = " + stmt, e); } }
From source file:dao.DirImageUpdateQuery.java
/** * This method is not called by spring.// ww w. jav a 2 s. c om * * @param conn the connection passed to this. * @param directoryid the category id * @param dirname the directory name * @param keywords the keywords * @param parentname the parent of this category or directory * @param stateid the state id * @param catdesc the category description * @param ownerid the owner id * @exception BaseDaoException */ public void run(Connection conn, String entryid, String directoryid, String zoom, String btitle, String caption) throws BaseDaoException { byte[] capBytes = { ' ' }; if (!RegexStrUtil.isNull(caption)) { capBytes = caption.getBytes(); } try { PreparedStatement stmt = conn.prepareStatement("update dirimages set caption=?, btitle='" + btitle + "', zoom=" + zoom + " where entryid=" + entryid + " and directoryid=" + directoryid + ""); stmt.setBytes(1, capBytes); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing update dirimages ", e); } }
From source file:dao.ShareuserUpdateQuery.java
/** * Method updates share user information for a given login * @param conn - the connection/* ww w . ja v a 2 s . c o m*/ * @param loginid - the loginid, who is sharing his/her information * @param destid - the destination loginid, the user with whom the information is being shared with * @param bphone - the bphone (of loginid) * @param cphone - the cphone (of loginid) * @param email - the email (of loginid) * @param files - the files (of loginid) * @throws BaseDaoException - when error occurs **/ public void run(Connection conn, String loginid, String destid, int bphone, int cphone, int email, int files) throws BaseDaoException { try { PreparedStatement stmt = conn.prepareStatement( "update shareuser set bphone=" + bphone + ", cphone=" + cphone + ", email=" + email + ", files=" + files + " where loginid=" + loginid + " and destid=" + destid + ""); stmt.executeUpdate(); } catch (Exception e) { logger.warn("Error occured while executing update shareuser ", e); throw new BaseDaoException("Error occured while executing update shareuser ", e); } }
From source file:mypackage.products.java
public int doUpdate(String query, String... params) { int changes = 0; try (Connection cn = Credentials.getConnection()) { PreparedStatement pstmt = cn.prepareStatement(query); for (int i = 1; i <= params.length; i++) { pstmt.setString(i, params[i - 1]); }//from ww w .jav a2 s . c om changes = pstmt.executeUpdate(); } catch (SQLException ex) { Logger.getLogger(products.class.getName()).log(Level.SEVERE, null, ex); } return changes; }