/** Note: Do NOT close these manually, they will be closed automatically. */ private PreparedStatement prepare(String sql, List<? extends Object> data) throws SQLException { if (!connected) { LOGGER.warning("connection closed then used!"); throw new SQLException("Connection closed then used!"); } PreparedStatement ps; if (mru.containsKey(sql)) { LOGGER.finest("Getting prepared statement from mru"); ps = mru.get(sql); } else { ps = con.prepareStatement(sql); LOGGER.finest("Storing prepared statement in mru"); mru.put(sql, ps); } ps.clearParameters(); if (data != null) { for (int i = 0; i < data.size(); i++) { Object obj = data.get(i); if (obj == null) { ps.setNull(i + 1, Types.NULL); // Not sure if this will work } else if (obj.getClass() == Integer.class) { ps.setInt(i + 1, (int) obj); } else if (obj.getClass() == Long.class) { ps.setLong(i + 1, (long) obj); } else if (obj.getClass() == Float.class) { ps.setFloat(i + 1, (float) obj); } else if (obj.getClass() == Double.class) { ps.setDouble(i + 1, (double) obj); } else if (obj.getClass() == String.class) { ps.setString(i + 1, (String) obj); } else if (obj.getClass() == Boolean.class) { ps.setBoolean(i + 1, (boolean) obj); } else { LOGGER.warning("Processing as object: " + obj.getClass()); ps.setObject(i + 1, obj); } } } if (sql.startsWith("SELECT")) { // Avoid converting the statement to a string if not going to be logged anyway if (LOGGER.isLoggable(Level.FINER)) { LOGGER.finer("Statement: " + ps.toString()); } } else { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Statement: " + ps.toString()); } } return ps; }