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:fll.db.NonNumericNominees.java
/** * Clear the nominees for the specified category at the tournament. * // w ww . j a v a2s . c o m * @param connection database connection * @param tournamentId the tournament * @param category the category * @throws SQLException */ public static void clearNominees(final Connection connection, final int tournamentId, final String category) throws SQLException { PreparedStatement delete = null; try { delete = connection.prepareStatement("DELETE FROM non_numeric_nominees"// + " WHERE tournament = ?"// + " AND category = ?"); delete.setInt(1, tournamentId); delete.setString(2, category); delete.executeUpdate(); } finally { SQLFunctions.close(delete); } }
From source file:net.codjo.dataprocess.server.treatmenthelper.TreatmentHelper.java
public static void insertRepository(Connection con, int repositoryId, String repositoryName) throws SQLException { PreparedStatement pStmt = con .prepareStatement("insert into PM_REPOSITORY (REPOSITORY_ID, REPOSITORY_NAME) values (?, ?)"); try {//from w w w.ja v a 2s .com pStmt.setInt(1, repositoryId); pStmt.setString(2, repositoryName); pStmt.executeUpdate(); } finally { pStmt.close(); } }
From source file:las.DBConnector.java
public static void insertTransactionIntoTable(Transaction transaction) throws SQLException { String data = "INSERT INTO TRANSACTIONS(MEMBER_ID, ITEM_ID)" + "Values (?,?)"; PreparedStatement pt = conn.prepareStatement(data); pt.setInt(1, transaction.getMemberID()); pt.setInt(2, transaction.getItemID()); try {//from w ww.ja v a 2 s. c om pt.executeUpdate(); } catch (Exception DerbySQLIntegrityConstraintViolationException) { JOptionPane.showMessageDialog(null, "Cannot Issue an item a member already owns!"); } }
From source file:com.l2jfree.gameserver.instancemanager.CursedWeaponsManager.java
public static void removeFromDb(int itemId) { Connection con = null;//from ww w. j a va2 s . co m try { con = L2DatabaseFactory.getInstance().getConnection(con); // Delete datas PreparedStatement statement = con.prepareStatement("DELETE FROM cursed_weapons WHERE itemId = ?"); statement.setInt(1, itemId); statement.executeUpdate(); statement.close(); } catch (SQLException e) { _log.fatal("CursedWeaponsManager: Failed to remove data: ", e); } finally { L2DatabaseFactory.close(con); } }
From source file:FacultyAdvisement.StudentRepository.java
public static void delete(DataSource ds, Student student) throws SQLException { Connection conn = ds.getConnection(); if (conn == null) { throw new SQLException("conn is null; Can't get db connection"); }/*from w w w .j a va 2 s . co m*/ try { PreparedStatement ps; ps = conn.prepareStatement("Delete from STUDENT where EMAIL=?"); ps.setString(1, student.getUsername()); ps.executeUpdate(); ps = conn.prepareStatement("Delete from USERTABLE where USERNAME=?"); ps.setString(1, student.getUsername()); ps.executeUpdate(); ps = conn.prepareStatement("Delete from GROUPTABLE where USERNAME=?"); ps.setString(1, student.getUsername()); ps.executeUpdate(); } finally { conn.close(); } //students = (HashMap<String, StudentPOJO>) readAll(); // reload the updated info }
From source file:com.silverpeas.notation.model.RatingDAO.java
public static long moveRatings(Connection con, ContributionRatingPK pk, final String componentInstanceId) throws SQLException { PreparedStatement prepStmt = con.prepareStatement(QUERY_MOVE_RATINGS); try {/*from w ww .j a v a 2 s .c o m*/ prepStmt.setString(1, componentInstanceId); prepStmt.setString(2, pk.getInstanceId()); prepStmt.setString(3, pk.getContributionId()); prepStmt.setString(4, pk.getContributionType()); return prepStmt.executeUpdate(); } finally { DBUtil.close(prepStmt); } }
From source file:at.becast.youploader.database.SQLite.java
/** * A simple SQL query without any return. * /* www . j ava 2 s . co m*/ * @param sql The SQL query * @throws SQLException */ public static void query(String sql) throws SQLException { PreparedStatement prest = null; prest = c.prepareStatement(sql); prest.executeUpdate(); prest.close(); }
From source file:ca.qc.adinfo.rouge.mail.db.MailDb.java
public static boolean setMailAsRead(DBManager dbManager, long mailId) { Connection connection = null; PreparedStatement stmt = null; ResultSet rs = null;//from ww w. j ava 2 s.c o m String sql = null; sql = "UPDATE rouge_mail SET `status` = ? WHERE `id` = ? "; try { connection = dbManager.getConnection(); stmt = connection.prepareStatement(sql); stmt.setString(1, "rea"); stmt.setLong(2, mailId); int ret = stmt.executeUpdate(); return (ret > 0); } catch (SQLException e) { log.error(stmt); log.error(e); return false; } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(connection); } }
From source file:ca.qc.adinfo.rouge.mail.db.MailDb.java
public static boolean deleteMail(DBManager dbManager, long mailId) { Connection connection = null; PreparedStatement stmt = null; ResultSet rs = null;/*from www.j a va2s . c om*/ String sql = null; sql = "UPDATE rouge_mail SET `status` = ? WHERE `id` = ? "; try { connection = dbManager.getConnection(); stmt = connection.prepareStatement(sql); stmt.setString(1, "del"); stmt.setLong(2, mailId); int ret = stmt.executeUpdate(); return (ret > 0); } catch (SQLException e) { log.error(stmt); log.error(e); return false; } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(connection); } }
From source file:ca.qc.adinfo.rouge.social.db.SocialDb.java
public static boolean addFriend(DBManager dbManager, long userId, long friendId) { Connection connection = null; PreparedStatement stmt = null; ResultSet rs = null;/*from w w w . j a va 2 s. com*/ String sql = null; sql = "INSERT INTO rouge_social_friends (`user_id`, `friend_user_id`) VALUES (?, ?)"; try { connection = dbManager.getConnection(); stmt = connection.prepareStatement(sql); stmt.setLong(1, userId); stmt.setLong(2, friendId); int ret = stmt.executeUpdate(); if (ret < 1) { return false; } stmt.setLong(1, friendId); stmt.setLong(2, userId); ret = stmt.executeUpdate(); return (ret > 0); } catch (SQLException e) { log.error(stmt); log.error(e); return false; } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(connection); } }