public PreparedStatement getPrepared(Object cacheKey) throws SQLException {
		SQLException exception = null;
		for (int i = MAX_QUERY_ATTEMPTS; --i >= 0;) {
			lock.lock();
			try {
				PrepStmt ps = stmtPreps.get(cacheKey);
				if (ps == null) {
					return null;
				} else if (ps.stmt != null) {
					return ps.stmt;
				}
				return ps.stmt = db.prepareStatement(ps.sql);
			} catch (SQLException ex) {
				if (isConnectionIssue(ex)) {
					exception = ex;
					reconnect();
				} else {
					System.err.println("SQL Error: " + ex.getErrorCode() + " "
							+ ex.getSQLState());
					throw ex;
				}
			} finally {
				lock.unlock();
			}
		}
		throw exception;
	}