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:com.concursive.connect.web.modules.profile.utils.ProjectUtils.java
/** * Rejects a project for the given user//from ww w . ja v a 2s .c o m * * @param db Description of the Parameter * @param projectId Description of the Parameter * @param userId Description of the Parameter * @throws SQLException Description of the Exception */ public static void reject(Connection db, int projectId, int userId) throws SQLException { // Remove the user... PreparedStatement pst = db.prepareStatement( "DELETE FROM project_team " + "WHERE project_id = ? " + "AND user_id = ? " + "AND status = ? "); pst.setInt(1, projectId); pst.setInt(2, userId); pst.setInt(3, TeamMember.STATUS_PENDING); pst.execute(); pst.close(); CacheUtils.invalidateValue(Constants.SYSTEM_PROJECT_CACHE, projectId); }
From source file:com.keybox.manage.db.UserDB.java
/** * updates existing user// w ww .j av a 2s . c o m * @param user user object */ public static void updateUserCredentials(User user) { Connection con = null; try { con = DBUtils.getConn(); String salt = EncryptionUtil.generateSalt(); PreparedStatement stmt = con.prepareStatement( "update users set first_nm=?, last_nm=?, email=?, username=?, user_type=?, password=?, salt=? where id=?"); stmt.setString(1, user.getFirstNm()); stmt.setString(2, user.getLastNm()); stmt.setString(3, user.getEmail()); stmt.setString(4, user.getUsername()); stmt.setString(5, user.getUserType()); stmt.setString(6, EncryptionUtil.hash(user.getPassword() + salt)); stmt.setString(7, salt); stmt.setLong(8, user.getId()); stmt.execute(); DBUtils.closeStmt(stmt); if (User.ADMINISTRATOR.equals(user.getUserType())) { PublicKeyDB.deleteUnassignedKeysByUser(con, user.getId()); } } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); }
From source file:com.hangum.tadpole.rdb.core.viewers.object.sub.utils.TadpoleObjectQuery.java
/** * update comment/*from ww w.j av a 2 s.co m*/ * * @param userDB * @param dao */ public static void updateComment(final UserDBDAO userDB, TableDAO dao) { java.sql.Connection javaConn = null; PreparedStatement stmt = null; try { SqlMapClient client = TadpoleSQLManager.getInstance(userDB); javaConn = client.getDataSource().getConnection(); if (userDB.getDBDefine() == DBDefine.ORACLE_DEFAULT | userDB.getDBDefine() == DBDefine.POSTGRE_DEFAULT | userDB.getDBDefine() == DBDefine.TIBERO_DEFAULT) { String strSQL = String.format("COMMENT ON TABLE %s IS %s", dao.getSysName(), SQLUtil.makeQuote(dao.getComment())); stmt = javaConn.prepareStatement(strSQL); try { stmt.execute(); } catch (Exception e) { // org.postgresql.util.PSQLException: No results were returned by the query. } } else if (userDB.getDBDefine() == DBDefine.MSSQL_8_LE_DEFAULT) { StringBuffer query = new StringBuffer(); query.append(" exec sp_dropextendedproperty 'MS_Description' ").append(", 'user' ,") .append(userDB.getUsers()).append(",'table' ").append(" , '").append(dao.getSysName()) .append("'"); stmt = javaConn.prepareStatement(query.toString()); stmt.execute(); query = new StringBuffer(); query.append(" exec sp_addextendedproperty 'MS_Description', '").append(dao.getComment()) .append("' ,'user' ,").append(userDB.getUsers()).append(",'table' ").append(" , '") .append(dao.getName()).append("'"); stmt = javaConn.prepareStatement(query.toString()); stmt.execute(); } else if (userDB.getDBDefine() == DBDefine.MSSQL_DEFAULT) { StringBuffer query = new StringBuffer(); query.append(" exec sp_dropextendedproperty 'MS_Description' ") .append(", 'schema' , " + dao.getSchema_name() + ",'table' ").append(" , '") .append(dao.getTable_name()).append("'"); stmt = javaConn.prepareStatement(query.toString()); stmt.execute(); query = new StringBuffer(); query.append(" exec sp_addextendedproperty 'MS_Description', '").append(dao.getComment()) .append("' ,'schema' , " + dao.getSchema_name() + " ,'table' ").append(" , '") .append(dao.getTable_name()).append("'"); stmt = javaConn.prepareStatement(query.toString()); stmt.execute(); } else if (userDB.getDBDefine() == DBDefine.MYSQL_DEFAULT || userDB.getDBDefine() == DBDefine.MARIADB_DEFAULT) { String strSQL = String.format("ALTER TABLE %s COMMENT %s", dao.getSysName(), SQLUtil.makeQuote(dao.getComment())); if (logger.isDebugEnabled()) logger.debug(strSQL); stmt = javaConn.prepareStatement(strSQL); stmt.execute(); } } catch (Exception e) { logger.error("Comment change error ", e); } finally { try { stmt.close(); } catch (Exception e) { } try { javaConn.close(); } catch (Exception e) { } } }
From source file:lineage2.gameserver.model.pledge.SubUnit.java
/** * Method removeMemberInDatabase./* w w w . jav a 2s . c o m*/ * @param member UnitMember */ private static void removeMemberInDatabase(UnitMember member) { Connection con = null; PreparedStatement statement = null; try { con = DatabaseFactory.getInstance().getConnection(); statement = con.prepareStatement( "UPDATE characters SET clanid=0, pledge_type=?, pledge_rank=0, lvl_joined_academy=0, apprentice=0, title='', leaveclan=? WHERE obj_Id=?"); statement.setInt(1, Clan.SUBUNIT_NONE); statement.setLong(2, System.currentTimeMillis() / 1000); statement.setInt(3, member.getObjectId()); statement.execute(); } catch (Exception e) { _log.warn("Exception: " + e, e); } finally { DbUtils.closeQuietly(con, statement); } }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.db.TagDAOImplTest.java
@AfterClass public static void cleanupDatabase() { final String statementStr1 = "DELETE FROM mmxApp WHERE appName LIKE '%" + APP_NAME_PREFIX + "%'"; final String statementStr2 = "DELETE FROM mmxDevice WHERE deviceId LIKE '%" + DEVICE_ID_PREFIX + "%'"; final String statementStr3 = "DELETE FROM ofUser WHERE username LIKE '%" + USERS_PREFIX + "%'"; final String statementStr4 = "DELETE FROM mmxTag WHERE tagname LIKE '%" + TAG_PREFIX + "%'"; final String statementStr5 = "DELETE FROM ofPubsubNode WHERE serviceID = 'pubsub'"; Connection conn = null;//from www . ja v a 2 s . c o m PreparedStatement pstmt1 = null; PreparedStatement pstmt2 = null; PreparedStatement pstmt3 = null; PreparedStatement pstmt4 = null; PreparedStatement pstmt5 = null; try { conn = UnitTestDSProvider.getDataSource().getConnection(); pstmt1 = conn.prepareStatement(statementStr1); pstmt2 = conn.prepareStatement(statementStr2); pstmt3 = conn.prepareStatement(statementStr3); pstmt4 = conn.prepareStatement(statementStr4); pstmt5 = conn.prepareStatement(statementStr5); pstmt1.execute(); pstmt2.execute(); pstmt3.execute(); pstmt4.execute(); pstmt5.execute(); } catch (SQLException e) { LOGGER.error("cleanupDatabase : {}", e); } finally { CloseUtil.close(LOGGER, pstmt1, conn); CloseUtil.close(LOGGER, pstmt2); CloseUtil.close(LOGGER, pstmt3); CloseUtil.close(LOGGER, pstmt4); CloseUtil.close(LOGGER, pstmt5); } }
From source file:at.becast.youploader.database.SQLite.java
public static void insertPlaylist(Item item, int account) throws SQLException, IOException { PreparedStatement prest = null; String sql = "INSERT INTO `playlists` (`name`, `playlistid`,`image`,`account`,`shown`) " + "VALUES (?,?,?,?,1)"; prest = c.prepareStatement(sql);/*from w w w . j av a 2s .co m*/ prest.setString(1, item.snippet.title); prest.setString(2, item.id); URL url = new URL(item.snippet.thumbnails.default__.url); InputStream is = null; is = url.openStream(); byte[] imageBytes = IOUtils.toByteArray(is); prest.setBytes(3, imageBytes); prest.setInt(4, account); prest.execute(); prest.close(); }
From source file:com.keybox.manage.db.SystemDB.java
/** * updates host system record/* ww w .j av a 2 s . c o m*/ * * @param hostSystem host system object */ public static void updateSystem(HostSystem hostSystem) { Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement( "update system set display_nm=?, user=?, host=?, port=?, authorized_keys=?, status_cd=? where id=?"); stmt.setString(1, hostSystem.getDisplayNm()); stmt.setString(2, hostSystem.getUser()); stmt.setString(3, hostSystem.getHost()); stmt.setInt(4, hostSystem.getPort()); stmt.setString(5, hostSystem.getAuthorizedKeys()); stmt.setString(6, hostSystem.getStatusCd()); stmt.setLong(7, hostSystem.getId()); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); }
From source file:com.keybox.manage.db.SystemDB.java
/** * inserts host system into DB/*from w w w. j a va 2s . c o m*/ * * @param hostSystem host system object * @return user id */ public static Long insertSystem(HostSystem hostSystem) { Connection con = null; Long userId = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement( "insert into system (display_nm, user, host, port, authorized_keys, status_cd) values (?,?,?,?,?,?)", PreparedStatement.RETURN_GENERATED_KEYS); stmt.setString(1, hostSystem.getDisplayNm()); stmt.setString(2, hostSystem.getUser()); stmt.setString(3, hostSystem.getHost()); stmt.setInt(4, hostSystem.getPort()); stmt.setString(5, hostSystem.getAuthorizedKeys()); stmt.setString(6, hostSystem.getStatusCd()); stmt.execute(); ResultSet rs = stmt.getGeneratedKeys(); if (rs.next()) { userId = rs.getLong(1); } DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); return userId; }
From source file:at.becast.youploader.database.SQLite.java
public static void savePlaylists(Playlists playlists, int account) throws SQLException, IOException { PreparedStatement prest = null; String sql = "INSERT INTO `playlists` (`name`, `playlistid`,`image`,`account`) " + "VALUES (?,?,?,?)"; for (Playlists.Item i : playlists.items) { prest = c.prepareStatement(sql); prest.setString(1, i.snippet.title); prest.setString(2, i.id);/* www .j a va2 s .c om*/ URL url = new URL(i.snippet.thumbnails.default__.url); InputStream is = null; is = url.openStream(); byte[] imageBytes = IOUtils.toByteArray(is); prest.setBytes(3, imageBytes); prest.setInt(4, account); prest.execute(); prest.close(); } }
From source file:org.openmrs.module.kenyaemr.chore.VoidDuplicateIdentifiersTest.java
/** * Helper method to execute SQL on the test database * @param sql the SQL statement//from w ww. j a va2s .c om */ private void executeSql(String sql) throws Exception { PreparedStatement ps = getConnection().prepareStatement(sql); ps.execute(); ps.close(); Context.clearSession(); }