List of usage examples for java.sql PreparedStatement clearParameters
void clearParameters() throws SQLException;
From source file:org.bml.util.geo.util.geolite.GISData.java
public static GISData fromIp(String ipAddress, PreparedStatement ps) throws UnknownHostException, SQLException { GISData data = new GISData(); ResultSet resultSet = null;/*from w w w . java 2 s. c o m*/ try { ps.clearParameters(); setInetAddress(ps, ipAddress); resultSet = ps.executeQuery(); if (resultSet.next()) { data.startIpNum = resultSet.getLong(1); data.endIpNum = resultSet.getLong(2); data.locId = resultSet.getLong(3); data.country = resultSet.getString(4); data.region = resultSet.getString(5); data.city = resultSet.getString(6); data.postalCode = resultSet.getString(7); data.latitude = resultSet.getFloat(8); data.longitude = resultSet.getFloat(9); data.metroCode = resultSet.getString(10); data.areaCode = resultSet.getString(11); } } catch (SQLException e) { LOG.warn("SQLException caught while obtaining GISData from IP=" + ipAddress); throw e; } finally { DbUtils.closeQuietly(resultSet); } return data; }
From source file:net.jmhertlein.mcanalytics.plugin.daemon.request.UniqueLoginsPerDayRequestHandler.java
@Override public JSONObject handle(Connection conn, StatementProvider stmts, JSONObject request, ClientMonitor client) throws Exception { PreparedStatement stmt = conn.prepareStatement(stmts.get(SQLString.GET_UNIQUE_LOGINS)); stmt.clearParameters(); stmt.setTimestamp(1, Timestamp.valueOf(LocalDate.parse(request.getString("start")).atStartOfDay())); stmt.setTimestamp(2,// w w w . ja v a 2 s. co m Timestamp.valueOf(LocalDate.parse(request.getString("end")).plusDays(1).atStartOfDay())); ResultSet res = stmt.executeQuery(); Map<String, Integer> counts = new HashMap<>(); while (res.next()) { counts.put(res.getTimestamp("login_day").toLocalDateTime().toLocalDate().toString(), res.getInt("login_count")); } JSONObject ret = new JSONObject(); ret.put("logins", counts); res.close(); stmt.close(); return ret; }
From source file:net.jmhertlein.mcanalytics.plugin.daemon.request.PastOnlinePlayerCountRequestHandler.java
@Override public JSONObject handle(Connection conn, StatementProvider stmts, JSONObject req, ClientMonitor c) throws SQLException { //System.out.println("Handler: starting..."); PreparedStatement stmt = conn.prepareStatement(stmts.get(SQLString.GET_HOURLY_PLAYER_COUNTS)); stmt.clearParameters(); stmt.setTimestamp(1, Timestamp.valueOf(LocalDateTime.parse(req.getString("start")))); stmt.setTimestamp(2, Timestamp.valueOf(LocalDateTime.parse(req.getString("end")))); ResultSet res = stmt.executeQuery(); Map<String, Integer> counts = new HashMap<>(); while (res.next()) { counts.put(res.getTimestamp("instant").toLocalDateTime().toString(), res.getInt("count")); }/* w w w . j a va 2 s. c o m*/ JSONObject ret = new JSONObject(); ret.put("counts", counts); res.close(); stmt.close(); conn.close(); //System.out.println("Handler: done, returning."); return ret; }
From source file:net.jmhertlein.mcanalytics.plugin.daemon.request.FirstJoinRequestHandler.java
@Override public JSONObject handle(Connection conn, StatementProvider stmts, JSONObject request, ClientMonitor client) throws Exception { //System.out.println("Handler: starting..."); PreparedStatement stmt = conn.prepareStatement(stmts.get(SQLString.GET_NEW_PLAYER_LOGINS_HOURLY)); stmt.clearParameters(); stmt.setTimestamp(1, Timestamp.valueOf(LocalDate.parse(request.getString("start")).atStartOfDay())); stmt.setTimestamp(2,/*w w w. j av a 2s. c o m*/ Timestamp.valueOf(LocalDate.parse(request.getString("end")).plusDays(1).atStartOfDay())); ResultSet res = stmt.executeQuery(); Map<String, Integer> counts = new HashMap<>(); while (res.next()) { counts.put(res.getTimestamp("hour_joined").toLocalDateTime().toString(), res.getInt("login_count")); } JSONObject ret = new JSONObject(); ret.put("first_login_counts", counts); res.close(); stmt.close(); //System.out.println("Handler: done, returning."); return ret; }
From source file:org.apereo.portal.i18n.RDBMLocaleStore.java
@Override public Locale[] getUserLocales(final IPerson person) { return jdbcOperations.execute(new ConnectionCallback<Locale[]>() { @Override/* w w w.j a v a 2s. c o m*/ public Locale[] doInConnection(Connection con) throws SQLException, DataAccessException { final List<Locale> localeList = new ArrayList<Locale>(); final String query = "SELECT * FROM UP_USER_LOCALE WHERE USER_ID=? ORDER BY PRIORITY"; final PreparedStatement pstmt = con.prepareStatement(query); try { pstmt.clearParameters(); pstmt.setInt(1, person.getID()); logger.debug(query); final ResultSet rs = pstmt.executeQuery(); try { while (rs.next()) { final String localeString = rs.getString("LOCALE"); final Locale locale = LocaleManager.parseLocale(localeString); localeList.add(locale); } } finally { rs.close(); } } finally { pstmt.close(); } return localeList.toArray(new Locale[localeList.size()]); } }); }
From source file:com.adito.jdbc.JDBCConnectionImpl.java
synchronized void releasePreparedStatement(String key, PreparedStatement ps) throws SQLException { ps.clearParameters(); Vector avail = (Vector) preparedStatements.get(key); avail.add(ps);/*from w ww . java 2 s . c om*/ }
From source file:org.accada.epcis.repository.capture.CaptureOperationsSession.java
public PreparedStatement getInsert(final String sql) throws SQLException { PreparedStatement ps = inserts.get(sql); if (ps == null) { ps = connection.prepareStatement(sql); inserts.put(sql, ps);// ww w . j av a2 s . co m } ps.clearParameters(); return ps; }
From source file:org.accada.epcis.repository.capture.CaptureOperationsSession.java
public PreparedStatement getSelect(final String sql) throws SQLException { PreparedStatement ps = selects.get(sql); if (ps == null) { ps = connection.prepareStatement(sql); selects.put(sql, ps);// w w w .ja v a2 s. c o m } ps.clearParameters(); return ps; }
From source file:org.apereo.portal.i18n.RDBMLocaleStore.java
@Override public void updateUserLocales(final IPerson person, final Locale[] locales) { this.transactionOperations.execute(new TransactionCallback<Object>() { @Override//from w w w . j a va 2 s .c om public Object doInTransaction(TransactionStatus status) { return jdbcOperations.execute(new ConnectionCallback<Object>() { @Override public Object doInConnection(Connection con) throws SQLException, DataAccessException { // Delete the existing list of locales final String delete = "DELETE FROM UP_USER_LOCALE WHERE USER_ID=?"; PreparedStatement pstmt = con.prepareStatement(delete); try { pstmt.clearParameters(); pstmt.setInt(1, person.getID()); logger.debug(delete); pstmt.executeUpdate(); } finally { pstmt.close(); } // Insert the new list of locales final String insert = "INSERT INTO UP_USER_LOCALE VALUES (?, ?, ?)"; pstmt = con.prepareStatement(insert); try { for (int i = 0; i < locales.length; i++) { pstmt.clearParameters(); pstmt.setInt(1, person.getID()); pstmt.setString(2, locales[i].toString()); pstmt.setInt(3, i); logger.debug(insert); pstmt.executeUpdate(); } } finally { pstmt.close(); } return null; } }); } }); }
From source file:org.accada.epcis.repository.capture.CaptureOperationsSession.java
public PreparedStatement getBatchInsert(final String sql) throws SQLException { PreparedStatement ps = batchInserts.get(sql); if (ps == null) { ps = connection.prepareStatement(sql); batchInserts.put(sql, ps);/*from w w w. j a v a2 s . co m*/ } ps.clearParameters(); return ps; }