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.CarryonRecentUpdateQuery.java
/** * This method is not called by spring.// w w w. j a va 2s .c o 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 btitle, String zoom, String entryid, String loginid, boolean isFile, String caption) throws BaseDaoException { byte[] capBytes = { ' ' }; if (!RegexStrUtil.isNull(caption)) { capBytes = caption.getBytes(); } /** * Zoom is not applicable to files. Don't update zoom for file blobs */ StringBuffer query = new StringBuffer(); try { if (isFile) { query.append("update pblob set btitle='" + btitle + "', caption='" + caption + "', zoom=" + zoom + " where entryid=" + entryid + " and loginid=" + loginid + ""); PreparedStatement stmt = conn.prepareStatement("update pblob set btitle='" + btitle + "', caption=? where entryid=" + entryid + " and loginid=" + loginid + ""); stmt.setBytes(1, capBytes); stmt.executeUpdate(); } else { query.append("update pblob set btitle='" + btitle + "', caption='" + caption + "', zoom=" + zoom + " where entryid=" + entryid + " and loginid=" + loginid + ""); PreparedStatement stmt = conn .prepareStatement("update pblob set btitle='" + btitle + "', caption=?, zoom=" + zoom + " where entryid=" + entryid + " and loginid=" + loginid + ""); stmt.setBytes(1, capBytes); stmt.executeUpdate(); } } catch (Exception e) { logger.warn("Error occured while executing CarryonRecentUpdateQuery, query=" + query.toString(), e); throw new BaseDaoException("Error occured while executing update pblob ", e); } }
From source file:genepi.db.DatabaseUpdater.java
public void executeSQLFile(String filename, String minVersion, String maxVersion) throws SQLException, IOException, URISyntaxException { String sqlContent = readFileAsStringFile(filename, minVersion, maxVersion); Connection connection = connector.getDataSource().getConnection(); PreparedStatement ps = connection.prepareStatement(sqlContent); ps.executeUpdate(); connection.close();// w ww . j av a 2 s .c o m }
From source file:dao.DirectoryScopeAddQuery.java
/** * This method is not called by spring.//from w w w.j a va 2s.c o m * This method is used to add scope for a directory * @param conn the connection passed to this. * @param directoryid the category id * @param permid the permission id * @param scopeid the scope id * @exception BaseDaoException */ public void run(Connection conn, String directoryid, String operations, String status, String scopeid) throws BaseDaoException { PreparedStatement query = null; String stmt = null; try { stmt = "insert into dirscope values (" + directoryid + ", " + operations + ", " + status + ", " + scopeid + ")"; query = conn.prepareStatement(stmt); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException( "Error occured while executing directory insert into dirscope, stmt = " + stmt, e); } }
From source file:net.mms_projects.copy_it.api.http.pages.android.RegisterGCM.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(); if (gcm_id.length() < 256) { GCMRunnable gcmRunnable = new GCMRunnable(); gcmRunnable.addRegistrationId(gcm_id); gcmRunnable.setDryRun();//w ww . jav a2 s.c o m JSONObject output = gcmRunnable.send(); if (output.optInt(SUCCESS, 0) == 1) { 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 { String error = output.getJSONArray(RESULTS).getJSONObject(0).getString(ERROR); throw new ErrorException(error); } } else throw new ErrorException(GCM_TOKEN_TOO_LONG); } else throw new ErrorException(MISSING_GCM_TOKEN); }
From source file:dao.CarryonUpdateQuery.java
/** * This method is not called by spring./*from www. j a va 2s . c o 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 btitle, String zoom, String entryid, String loginid, boolean isFile, String caption) throws BaseDaoException { byte[] capBytes = { ' ' }; if (!RegexStrUtil.isNull(caption)) { capBytes = caption.getBytes(); } /** * Zoom is not applicable to files. Don't update zoom for file blobs */ StringBuffer query = new StringBuffer(); try { if (isFile) { query.append("update carryon set btitle='" + btitle + "', caption='" + caption + "', zoom=" + zoom + " where entryid=" + entryid + " and loginid=" + loginid + ""); PreparedStatement stmt = conn.prepareStatement("update carryon set btitle='" + btitle + "', caption=? where entryid=" + entryid + " and loginid=" + loginid + ""); stmt.setBytes(1, capBytes); stmt.executeUpdate(); } else { query.append("update carryon set btitle='" + btitle + "', caption='" + caption + "', zoom=" + zoom + " where entryid=" + entryid + " and loginid=" + loginid + ""); PreparedStatement stmt = conn .prepareStatement("update carryon set btitle='" + btitle + "', caption=?, zoom=" + zoom + " where entryid=" + entryid + " and loginid=" + loginid + ""); stmt.setBytes(1, capBytes); stmt.executeUpdate(); } } catch (Exception e) { logger.warn("Error occured while executing CarryonUpdateQuery, query=" + query.toString(), e); throw new BaseDaoException("Error occured while executing update carryon ", e); } }
From source file:ASSINGMENT4.ServletProducts.java
private void doPostOrPutOrDelete(String query, String... params) { try (Connection conn = getConnection()) { PreparedStatement pstmt = conn.prepareStatement(query); for (int i = 1; i <= params.length; i++) { pstmt.setString(i, params[i - 1]); }/*w w w . j av a 2 s . com*/ pstmt.executeUpdate(); } catch (SQLException ex) { Logger.getLogger(ServletProducts.class.getName()).log(Level.SEVERE, null, ex); } getResults("SELECT * FROM product"); }
From source file:genepi.db.DatabaseUpdater.java
public void executeSQLClasspath(InputStream is, String minVersion, String maxVersion) throws SQLException, IOException, URISyntaxException { String sqlContent = readFileAsStringClasspath(is, minVersion, maxVersion); if (!sqlContent.isEmpty()) { Connection connection = connector.getDataSource().getConnection(); PreparedStatement ps = connection.prepareStatement(sqlContent); ps.executeUpdate(); connection.close();/*w w w.ja v a2 s .co m*/ } }
From source file:dao.UserAddCobrandQuery.java
/** * This method is not called by spring.//from w w w . j a va 2 s .co m * * @param conn the connection passed to this. * @param loginid the loginid * @param header the header * @param footer the footer * @exception BaseDaoException */ public void run(Connection conn, String loginid, byte[] header, byte[] footer) throws BaseDaoException { PreparedStatement query = null; String stmt = null; try { stmt = "insert into usercobrand values(" + loginid + ", ?, ?)"; query = conn.prepareStatement(stmt); query.setBytes(1, header); query.setBytes(2, footer); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing usercobrand inserting query, query = " + stmt, e); } }