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.DirTrafficAddQuery.java
/** * This method is not called by spring.// www .j a v a 2 s. co m * This method adds visitor information for a directory * @param conn the connection passed to this. * @param dirid the directory id * @param visitorid the visitor id for this directory * @param referer the referer that sent this visitor to the directory * @param ipaddress the ipaddress of this visitor * @exception BaseDaoException */ public void run(Connection conn, String dirid, String visitorid, String referer, String ipaddress) throws BaseDaoException { byte[] byteReferer = { ' ' }; if (!RegexStrUtil.isNull(referer)) { byteReferer = referer.getBytes(); } String stmt = "insert delayed into dirtraffic values (0, " + dirid + ", " + visitorid + ", ?, '" + ipaddress + "', CURRENT_TIMESTAMP())"; try { PreparedStatement query = conn.prepareStatement(stmt); query.setBytes(1, byteReferer); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing DirTrafficAddQuery(), " + stmt, e); } }
From source file:de.static_interface.reallifeplugin.module.contract.database.table.ContractUsersTable.java
@Override public void create() throws SQLException { String sql;/*from w w w. j av a2 s. com*/ switch (db.getType()) { case H2: sql = "CREATE TABLE IF NOT EXISTS " + getName() + " (" + "id INT NOT NULL AUTO_INCREMENT PRIMARY KEY," + "uuid VARCHAR(36) NOT NULL" + ");"; break; case MYSQL: default: sql = "CREATE TABLE IF NOT EXISTS `" + getName() + "` (" + "`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY," + "`uuid` VARCHAR(36) NOT NULL" + ");"; break; } PreparedStatement statement = db.getConnection().prepareStatement(sql); statement.executeUpdate(); statement.close(); }
From source file:com.sf.ddao.ops.UpdateSqlOperation.java
public boolean execute(Context context) throws Exception { try {//from w w w . ja va2s .com final MethodCallCtx callCtx = CtxHelper.get(context, MethodCallCtx.class); PreparedStatement preparedStatement = statementFactory.createStatement(context, false); int res = preparedStatement.executeUpdate(); preparedStatement.close(); if (method.getReturnType() == Integer.TYPE || method.getReturnType() == Integer.class) { callCtx.setLastReturn(res); } return CONTINUE_PROCESSING; } catch (Exception t) { throw new DaoException("Failed to execute sql operation for " + method, t); } }
From source file:com.wso2telco.dbUtil.DataBaseConnectUtils.java
/** * Update user details in Back Channeling Scenario : update Session ID * * @param sessionId ID of the session * @param correlationId unique ID of the user *//* w w w .j av a 2 s .c o m*/ public static void updateSessionIdInBackChannel(String correlationId, String sessionId) throws ConfigurationException, CommonAuthenticatorException { Connection connection = null; PreparedStatement preparedStatement = null; String updateUserDetailsQuery = null; updateUserDetailsQuery = "update backchannel_request_details set session_id=? where correlation_id=?;"; try { connection = getConnectDBConnection(); if (log.isDebugEnabled()) { log.debug("Executing the query " + updateUserDetailsQuery); } preparedStatement = connection.prepareStatement(updateUserDetailsQuery); preparedStatement.setString(1, sessionId); preparedStatement.setString(2, correlationId); preparedStatement.executeUpdate(); } catch (SQLException e) { handleException("Error occurred while updating user details for : " + correlationId + "in " + "BackChannel Scenario.", e); } catch (NamingException e) { throw new ConfigurationException("DataSource could not be found in mobile-connect.xml"); } finally { closeAllConnections(preparedStatement, connection); } }
From source file:DelProductWS.DelProductWS.java
@WebMethod(operationName = "delProduct") public int delProduct(@WebParam(name = "access_token") String access_token, @WebParam(name = "product_id") String product_id) throws IOException, ParseException { int status = 0; Connection dbConn = 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"); switch (statusResp) { case "valid": try {/*from w w w .j a v a2s .c o m*/ String query = "DELETE FROM catalogue 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; }
From source file:dao.YourkeywordsDeleteQuery.java
/** * This method deletes yourkeywords // w w w .j a va2 s. co m * @param conn - the connection * @param loginid - the loginid * @throws BaseDaoException - when error occurs * Used as part of the transaction, skip LOW_PRIORITY **/ public void run(Connection conn, String loginid) throws BaseDaoException { try { PreparedStatement stmt = conn .prepareStatement("delete from yourkeywords where loginid=" + loginid + ""); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing yourkeywordsdelete query ", e); } }
From source file:logout.logout_servlet.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from w w w . j a va2 s. com*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String token = request.getParameter("access_token"); Connection currentCon = null; JSONObject arrayObj = new JSONObject(); String query = "DELETE FROM tokendata WHERE token ='" + token + "'"; try { //connect to database currentCon = ConnectionManager.getConnection(); PreparedStatement ps = currentCon.prepareStatement(query); int i = ps.executeUpdate(); arrayObj.put("status", "ok"); System.out.println("DELETE TOKEN"); } catch (Exception ex) { System.out.println("Log out failed: An Exception has occurred! " + ex); } finally { if (currentCon != null) { try { currentCon.close(); } catch (Exception e) { } currentCon = null; } } response.setContentType("application/json:charset=UTF-8"); response.getWriter().write(arrayObj.toString()); }
From source file:com.fufang.testcase.his.GetMaterialContents.java
@AfterTest public void deleteSql() throws SQLException { SqlUtils c = new SqlUtils(); Connection Conn = c.mySqlConnection(dbUrl, dbUserName, dbPassword); String sql = "DELETE FROM HISFC.t_community_contents WHERE communityId = '200301';"; try {//w w w . ja v a 2 s . co m PreparedStatement pstmt = Conn.prepareStatement(sql); pstmt.executeUpdate(); sql = "DELETE FROM HISFC.t_contents_item WHERE contentsItemId in ('031bbb2f-bda6-4c29-8e8a-c34e3cdca46d','03281538-cfc7-4917-a73f-e4cfe2dd9da6')"; pstmt.executeUpdate(sql); } catch (SQLException e) { e.printStackTrace(); } finally { try { if (Con != null) Con.close(); } catch (SQLException se) { se.printStackTrace(); } } }
From source file:com.flexive.core.security.FxDBAuthentication.java
/** * Mark a user as no longer active in the database. * * @param ticket the ticket of the user//from www. j a v a2 s . c o m * @throws javax.security.auth.login.LoginException * if the function failed */ public static void logout(UserTicket ticket) throws LoginException { PreparedStatement ps = null; String curSql; Connection con = null; FxContext inf = FxContext.get(); try { // Obtain a database connection con = Database.getDbConnection(); // EJBLookup user in the database, combined with a update statement to make sure // nothing changes between the lookup/set ISLOGGEDIN flag. curSql = "UPDATE " + TBL_ACCOUNT_DETAILS + " SET ISLOGGEDIN=? WHERE ID=? AND APPLICATION=?"; ps = con.prepareStatement(curSql); ps.setBoolean(1, false); ps.setLong(2, ticket.getUserId()); ps.setString(3, inf.getApplicationId()); // Not more than one row should be affected, or the logout failed final int rowCount = ps.executeUpdate(); if (rowCount > 1) { // Logout failed. LoginException le = new LoginException("Logout for user [" + ticket.getUserId() + "] failed"); LOG.error(le); throw le; } } catch (SQLException exc) { LoginException le = new LoginException("Database error: " + exc.getMessage()); LOG.error(le); throw le; } finally { Database.closeObjects(FxDBAuthentication.class, con, ps); } }
From source file:dao.DeleteColBlobIndexQuery.java
/** * This method is used to delete a blob indexes in a collabrum * @param conn the connection//from w w w . j a v a2 s . c o m * @param eid the entry id for the collabrum blob * @exception BaseDaoException */ public void run(Connection conn, String entryId) throws BaseDaoException { try { PreparedStatement stmt = conn .prepareStatement("delete from collblob_ind where entryid=" + entryId + ""); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException( "Error while executing db query, delete from collblob_ind where entryid=" + entryId, e); } }