ps = conn.prepareStatement(getSQLStatement("SELECT_COUNTER"));
String selectCounterSQL = getSQLStatement("SELECT_COUNTER");  ps = conn.prepareStatement(selectCounterSQL);
   public long reserveIDBlock(String counterName, int size) throws Exception   {      //TODO This will need locking (e.g. SELECT ... FOR UPDATE...) in the clustered case             if (trace) { log.trace("Getting id block for counter: " + counterName + " ,size: " + size); }            if (size <= 0)      {         throw new IllegalArgumentException("block size must be > 0");      }            Connection conn = null;      PreparedStatement ps = null;      ResultSet rs = null;      TransactionWrapper wrap = new TransactionWrapper();            try      {         conn = ds.getConnection();                  ps = conn.prepareStatement(getSQLStatement("SELECT_COUNTER"));                  ps.setString(1, counterName);                  rs = ps.executeQuery();                  if (!rs.next())         {            rs.close();            rs = null;                        ps.close();                        ps = conn.prepareStatement(getSQLStatement("INSERT_COUNTER"));                        ps.setString(1, counterName);                        ps.setLong(2, size);                        int rows = ps.executeUpdate();                        if (trace) {  log.trace(JDBCUtil.statementToString(getSQLStatement("INSERT_COUNTER"), counterName)                           + " inserted " + rows + " rows"); }                          ps.close();                        ps = null;                        return 0;         }                  if (trace) { log.trace(JDBCUtil.statementToString(getSQLStatement("SELECT_COUNTER"), counterName)); }                  long nextId = rs.getLong(1);                  rs.close();         rs = null;                  ps.close();                  ps = conn.prepareStatement(getSQLStatement("UPDATE_COUNTER"));                  ps.setLong(1, nextId + size);                  ps.setString(2, counterName);                  int rows = ps.executeUpdate();                  if (trace) { log.trace(JDBCUtil.statementToString(getSQLStatement("UPDATE_COUNTER"), new Long(nextId + size),                               counterName) + " updated " + rows + " rows"); }                          return nextId;      }      catch (Exception e)      {         wrap.exceptionOccurred();         throw e;      }      finally      {         if (ps != null)         {            try            {               ps.close();            }            catch (Throwable e)            {            }         }         if (conn != null)         {            try            {               conn.close();            }            catch (Throwable e)            {            }         }         wrap.end();      }        }