public static void Update(Unlocked p) throws ResponseException { PreparedStatement statement = null; String query = "Update unlocked SET fk_profile_id=?,bonus_info=?,content_info=? where fk_profile_id=?;"; Connection connect = null; IConnection c = MiscUtil.getIConnection(); try { connect = c.init(); statement = connect.prepareStatement(query); statement.setLong(1, p.getProfileId()); statement.setString(2, p.getBonusInfo()); statement.setString(3, p.getContentInfo()); statement.setLong(4, p.getProfileId()); statement.executeUpdate(); } catch (SQLException e) { logger.error("SQL Error", e); throw new ResponseException("SQL Error", HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } catch (ResponseException e) { throw e; } finally { try { if (statement != null) statement.close(); if (connect != null) connect.close(); } catch (SQLException e) { logger.error("SQL Error", e); } } }
public static ResultSet Read() throws ResponseException { ResultSet rs = null; PreparedStatement statement = null; String query = "select * from unlocked;"; Connection connect = null; CachedRowSet crs = null; IConnection c = MiscUtil.getIConnection(); try (CachedRowSet crs2 = RowSetProvider.newFactory().createCachedRowSet()) { connect = c.init(); statement = connect.prepareStatement(query); rs = statement.executeQuery(); crs2.populate(rs); crs = crs2.createCopy(); } catch (SQLException e) { logger.error("SQL Error", e); throw new ResponseException("SQL Error", HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } catch (ResponseException e) { throw e; } finally { try { if (statement != null) statement.close(); if (connect != null) connect.close(); } catch (SQLException e) { logger.error("SQL Error", e); } } return (crs); }