List of usage examples for java.sql PreparedStatement execute
boolean execute() throws SQLException;
PreparedStatement
object, which may be any kind of SQL statement. From source file:at.becast.youploader.database.SQLite.java
public static Boolean updateUploadData(Video data, VideoMetadata metadata, int id) throws SQLException, IOException { PreparedStatement prest = null; ObjectMapper mapper = new ObjectMapper(); String sql = "UPDATE `uploads` SET `data`=?,`metadata`=? WHERE `id`=?"; prest = c.prepareStatement(sql);// w w w.ja v a 2s . co m prest.setString(1, mapper.writeValueAsString(data)); prest.setString(2, mapper.writeValueAsString(metadata)); prest.setInt(3, id); boolean res = prest.execute(); prest.close(); return res; }
From source file:com.keybox.manage.db.PublicKeyDB.java
/** * Deletes all SSH keys for users that are not assigned in a profile * * @param con DB connection//from w w w . ja v a 2 s .c o m * @param profileId profile id */ public static void deleteUnassignedKeysByProfile(Connection con, Long profileId) { try { PreparedStatement stmt = con.prepareStatement( "delete from public_keys where profile_id=? and user_id not in (select user_id from user_map where profile_id=?)"); stmt.setLong(1, profileId); stmt.setLong(2, profileId); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } }
From source file:at.becast.youploader.database.SQLite.java
public static Boolean prepareUpload(int id, String Url, String yt_id) { PreparedStatement prest = null; String sql = "UPDATE `uploads` SET `status`=?,`url`=?,`yt_id`=? WHERE `id`=?"; try {/* www .ja va 2s . c o m*/ prest = c.prepareStatement(sql); prest.setString(1, UploadManager.Status.PREPARED.toString()); prest.setString(2, Url); prest.setString(3, yt_id); prest.setInt(4, id); boolean res = prest.execute(); prest.close(); return res; } catch (SQLException e) { LOG.error("Error preparing upload", e); return false; } }
From source file:at.becast.youploader.database.SQLite.java
public static Boolean updateUpload(int account, File file, Video data, String enddir, VideoMetadata metadata, int id) throws SQLException, IOException { PreparedStatement prest = null; String sql = "UPDATE `uploads` SET `account`=?, `file`=?, `lenght`=?, `enddir`=? WHERE `id`=?"; prest = c.prepareStatement(sql);/*w w w . j av a 2s. com*/ prest.setInt(1, account); prest.setString(2, file.getAbsolutePath()); prest.setLong(3, file.length()); prest.setString(4, enddir); prest.setInt(5, id); boolean res = prest.execute(); prest.close(); boolean upd = updateUploadData(data, metadata, id); return res && upd; }
From source file:com.wso2.raspberrypi.Util.java
public static void updateRaspberryPi(RaspberryPi raspberryPi) { BasicDataSource ds = getBasicDataSource(); Connection dbConnection = null; PreparedStatement prepStmt = null; try {/*from www . j a va2 s . co m*/ dbConnection = ds.getConnection(); prepStmt = dbConnection.prepareStatement("UPDATE RASP_PI SET blink=" + raspberryPi.isBlink() + ",reboot=" + raspberryPi.isReboot() + ",selected=" + raspberryPi.isSelected() + ",label='" + raspberryPi.getLabel() + "'" + " where mac='" + raspberryPi.getMacAddress() + "'"); prepStmt.execute(); } catch (SQLException e) { e.printStackTrace(); } finally { try { if (dbConnection != null) { dbConnection.close(); } if (prepStmt != null) { prepStmt.close(); } } catch (SQLException e) { e.printStackTrace(); } } }
From source file:com.keybox.manage.db.PublicKeyDB.java
/** * Deletes all SSH keys for users that are not assigned in a profile * * @param con DB connection//from ww w .j a v a2s .co m * @param userId user id */ public static void deleteUnassignedKeysByUser(Connection con, Long userId) { try { PreparedStatement stmt = con.prepareStatement( "delete from public_keys where (profile_id is null or profile_id not in (select profile_id from user_map where user_id=?)) and user_id=?"); stmt.setLong(1, userId); stmt.setLong(2, userId); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } }
From source file:edu.jhu.pha.vospace.storage.SwiftStorageManager.java
public static String generateRandomCredentials(final String username) { return DbPoolServlet.goSql("Generate random credentials", "select username, apikey from storage_users_pool where user_id IS NULL limit 1;", new SqlWorker<String>() { @Override// w w w .j a va 2 s . co m public String go(Connection conn, PreparedStatement stmt) throws SQLException { ResultSet rs = stmt.executeQuery(); if (rs.next()) { String user = rs.getString("username"); String password = rs.getString("apikey"); PreparedStatement prep = conn.prepareStatement( "update storage_users_pool SET user_id = (select user_id from user_identities where identity = ?) where username = ?"); prep.setString(1, username); prep.setString(2, user); prep.execute(); logger.debug(username + " " + user); StringWriter writer = new StringWriter(); JsonFactory f = new JsonFactory(); try { JsonGenerator g = f.createJsonGenerator(writer); g.writeStartObject(); g.writeStringField("username", user); g.writeStringField("apikey", password); g.writeEndObject(); g.close(); // important: will force flushing of output, close underlying output stream return writer.getBuffer().toString(); } catch (JsonGenerationException ex) { throw new InternalServerErrorException( "Error generating user storage credentials. " + ex.getMessage()); } catch (IOException e) { throw new InternalServerErrorException( "Error generating user storage credentials. " + e.getMessage()); } } else throw new PermissionDeniedException("The user does not exist."); } }); }
From source file:com.hangum.tadpole.rdb.core.util.bander.oracle.OracleExecutePlanUtils.java
/** * oracle query plan? . //from w w w . ja v a 2s . c o m * * @param userDB * @param sql * @param planTableName * @throws Exception */ public static void plan(UserDBDAO userDB, String sql, String planTableName, java.sql.Connection javaConn, PreparedStatement stmt, String statement_id) throws Exception { //java.sql.Connection javaConn = null; //PreparedStatement stmt = null; //ResultSet rs = null; try { //SqlMapClient client = TadpoleSQLManager.getInstance(userDB); //javaConn = client.getDataSource().getConnection(); String query = PartQueryUtil.makeExplainQuery(userDB, sql); query = StringUtils.replaceOnce(query, PublicTadpoleDefine.STATEMENT_ID, statement_id); query = StringUtils.replaceOnce(query, PublicTadpoleDefine.DELIMITER, planTableName); stmt = javaConn.prepareStatement(query); //stmt = javaConn.prepareStatement( StringUtils.replaceOnce(PartQueryUtil.makeExplainQuery(userDB, sql), PublicTadpoleDefine.DELIMITER, planTableName)); stmt.execute(); } finally { //if(rs != null) rs.close(); //if(stmt != null) stmt.close(); //if(javaConn != null) javaConn.close(); } }
From source file:com.concursive.connect.web.modules.profile.utils.ProjectUtils.java
public static synchronized String updateUniqueId(Connection db, int projectId, String title) throws SQLException { if (projectId == -1) { throw new SQLException("ID was not specified"); }//from w w w . java 2s. com if (title == null) { throw new SQLException("Title was not specified"); } // reserve a unique text id for the project String uniqueId = ProjectUtils.generateUniqueId(title, projectId, db); PreparedStatement pst = db .prepareStatement("UPDATE projects " + "SET projecttextid = ? " + "WHERE project_id = ?"); pst.setString(1, uniqueId); pst.setInt(2, projectId); pst.execute(); pst.close(); CacheUtils.invalidateValue(Constants.SYSTEM_PROJECT_CACHE, projectId); CacheUtils.invalidateValue(Constants.SYSTEM_PROJECT_UNIQUE_ID_CACHE, uniqueId); return uniqueId; }
From source file:at.becast.youploader.database.SQLite.java
public static void updatePlaylist(Item item) throws SQLException, IOException { PreparedStatement prest = null; String sql = "UPDATE `playlists` SET `name`=?,`image`=? WHERE `playlistid`=?"; prest = c.prepareStatement(sql);//from w w w . j a va 2 s . co m prest.setString(1, item.snippet.title); URL url = new URL(item.snippet.thumbnails.default__.url); InputStream is = null; is = url.openStream(); byte[] imageBytes = IOUtils.toByteArray(is); prest.setBytes(2, imageBytes); prest.setString(3, item.id); prest.execute(); prest.close(); }