List of usage examples for java.sql PreparedStatement setInt
void setInt(int parameterIndex, int x) throws SQLException;
int
value. From source file:net.sf.l2j.gameserver.model.entity.Couple.java
public void divorce() { java.sql.Connection con = null; try {/*from ww w .j a va2s . co m*/ con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement; statement = con.prepareStatement("DELETE FROM couples WHERE id=?"); statement.setInt(1, _Id); statement.execute(); } catch (Exception e) { _log.error("Exception: Couple.divorce(): " + e.getMessage(), e); } finally { try { con.close(); } catch (Exception e) { } } }
From source file:org.cbioportal.database.annotator.AnnotateRecordsWriter.java
private void updateMutationsInDb(MutationEvent eventToBeDeleted, MutationEvent properlyAnnotatedEvent) throws Exception { PreparedStatement pstmt = con .prepareStatement("UPDATE mutation set mutation_event_id = ? where mutation_event_id = ?"); pstmt.setInt(1, properlyAnnotatedEvent.getMUTATION_EVENT_ID()); pstmt.setInt(2, eventToBeDeleted.getMUTATION_EVENT_ID()); pstmt.executeUpdate();// w ww. j av a 2 s .co m log.info( "Updating mutations - mutations linked to mutation event " + eventToBeDeleted.getMUTATION_EVENT_ID() + " now linked to " + properlyAnnotatedEvent.getMUTATION_EVENT_ID()); }
From source file:dhbw.clippinggorilla.objects.user.UserUtils.java
private static Set<LocalTime> loadAllClippingSendTimes(User u) { Set<LocalTime> times = new HashSet<>(); try {/*from w ww .j av a 2s . com*/ String sql = "SELECT * FROM " + Tables.USER_CLIPPING_TIMES + " WHERE " + Columns.USER_ID + " = ?"; PreparedStatement statement = Database.getConnection().prepareStatement(sql); statement.setInt(1, u.getId()); ResultSet result = statement.executeQuery(); while (result.next()) { times.add(LocalTime.parse(result.getString(Columns.CLIPPING_TIME))); } } catch (SQLException ex) { Log.warning("Sql failed: loadClippingTime", ex); } return times; }
From source file:com.oracle.products.ProductResource.java
@GET @Path("{id}") @Produces(MediaType.APPLICATION_JSON)// w w w. j ava 2 s . c om public String getproduct(@PathParam("id") int id) throws SQLException { if (conn == null) { return "not connected"; } else { String query = "Select * from product where product_id = ?"; PreparedStatement pstmt = conn.prepareStatement(query); pstmt.setInt(1, id); ResultSet rs = pstmt.executeQuery(); String result = ""; JSONArray productArr = new JSONArray(); while (rs.next()) { Map productMap = new LinkedHashMap(); productMap.put("productID", rs.getInt("product_id")); productMap.put("name", rs.getString("name")); productMap.put("description", rs.getString("description")); productMap.put("quantity", rs.getInt("quantity")); productArr.add(productMap); } result = productArr.toString(); return result; } }
From source file:dhbw.clippinggorilla.objects.user.UserUtils.java
/** * Sets status of user to 0, which effectively bans him. * * @param u The User sho sould be banned * @return true if successful, otherwise: false *///from ww w.j a v a2 s . c o m public static boolean banUser(User u) { Log.info("Banning user " + u.getUsername()); try { String sql = "UPDATE " + Tables.USER + " SET " + Columns.STATUS + " = ? WHERE " + Columns.ID + " = ?"; PreparedStatement statement = Database.getConnection().prepareStatement(sql); statement.setInt(1, 0); statement.setInt(2, u.getId()); statement.executeUpdate(); u.setAccessLevel(0); return true; } catch (SQLException ex) { Log.warning("Failed banning user " + u.getUsername(), ex); return false; } }
From source file:dhbw.clippinggorilla.objects.user.UserUtils.java
/** * Sets status of user to 20, which effectively unbans him. * * @param u The User whose should be unbanned * @return true if successful, otherwise: false *//*from ww w.j a va2 s .c om*/ public static boolean pardonUser(User u) { Log.info("Pardoning user " + u.getUsername()); try { String sql = "UPDATE " + Tables.USER + " SET " + Columns.STATUS + " = ? WHERE " + Columns.ID + " = ?"; PreparedStatement statement = Database.getConnection().prepareStatement(sql); statement.setInt(1, 20); statement.setInt(2, u.getId()); statement.executeUpdate(); u.setAccessLevel(20); return true; } catch (SQLException ex) { Log.warning("Failed pardoning user " + u.getUsername(), ex); return false; } }
From source file:dhbw.clippinggorilla.objects.user.UserUtils.java
/** * Sets status of user to 90, which effectively makes him a Admin. * * @param u The User who should be an admin * @return true if successful, otherwise: false *///from w ww . j a v a2 s .com public static boolean opUser(User u) { Log.info("Opping user " + u.getUsername()); try { String sql = "UPDATE " + Tables.USER + " SET " + Columns.STATUS + " = ? WHERE " + Columns.ID + " = ?"; PreparedStatement statement = Database.getConnection().prepareStatement(sql); statement.setInt(1, 90); statement.setInt(2, u.getId()); statement.executeUpdate(); u.setAccessLevel(90); return true; } catch (SQLException ex) { Log.warning("Failed opping user " + u.getUsername(), ex); return false; } }
From source file:dhbw.clippinggorilla.objects.user.UserUtils.java
/** * Removes a user/* w w w . ja va 2 s . c om*/ * * @param u The User who should be deleted */ public static void removeUser(User u) { String sql = "DELETE FROM " + Tables.USER + " WHERE " + Columns.ID + " = ?"; try { PreparedStatement statement = Database.getConnection().prepareStatement(sql); statement.setInt(1, u.getId()); statement.executeUpdate(); } catch (SQLException ex) { Log.warning("Sql failed: removeUser", ex); } USERS.values().remove(u); USERS_PER_EMAIL.values().remove(u); USERS_PER_ID.values().remove(u); USERS_PER_USERNAME.values().remove(u); }
From source file:com.l2jfree.gameserver.datatables.HennaTreeTable.java
private HennaTreeTable() { int classId = 0; int count = 0; Connection con = null;/*from w w w . jav a 2 s . co m*/ try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement("SELECT id FROM class_list"); ResultSet classlist = statement.executeQuery(); while (classlist.next()) { classId = classlist.getInt("id"); FastList<L2Henna> list = new FastList<L2Henna>(); PreparedStatement statement2 = con .prepareStatement("SELECT symbol_id FROM henna_trees where class_id=?"); statement2.setInt(1, classId); ResultSet hennatree = statement2.executeQuery(); while (hennatree.next()) { int id = hennatree.getInt("symbol_id"); L2Henna template = HennaTable.getInstance().getTemplate(id); if (template == null) { hennatree.close(); statement2.close(); classlist.close(); statement.close(); return; } list.add(template); } hennatree.close(); statement2.close(); count += list.size(); _hennaTrees.put(classId, list.toArray(new L2Henna[list.size()])); } classlist.close(); statement.close(); _log.info("HennaTreeTable: Loaded " + count + " Henna Tree Templates."); } catch (Exception e) { _log.warn("Error while creating henna tree for classId " + classId + " ", e); } finally { L2DatabaseFactory.close(con); } }
From source file:dhbw.clippinggorilla.objects.user.UserUtils.java
/** * Adds a new Clipping sending time for a User * * @param u The User of the new Clipping sending time * @param time The Time of the clipping being send * @return true if successful, false otherwise *///from w w w .j a v a2s .c o m public static boolean addClippingSendTime(User u, LocalTime time) { try { String sql = "INSERT INTO " + Tables.USER_CLIPPING_TIMES + " (" + Columns.USER_ID + ", " + Columns.CLIPPING_TIME + ") VALUES (?, ?)"; PreparedStatement statement = Database.getConnection().prepareStatement(sql); statement.setInt(1, u.getId()); statement.setString(2, time.toString()); statement.executeUpdate(); } catch (SQLException ex) { Log.warning("Sql failed: addClippingTime", ex); return false; } u.getClippingTime().add(time); Jobs.updateClippingGenerationTimes(u, u.getClippingTime()); return true; }