skip to main content
Using the Driver : Statement Pool Monitor : Using DataDirect-Specific Methods to Access the Statement Pool Monitor : Generating a List of Statements in the Statement Pool
  

Try DataDirect Drivers Now
Generating a List of Statements in the Statement Pool
The following code shows how to return an ExtStatementPoolMonitor object using a connection and how to generate a list of statements in the statement pool associated with the connection.
Note: The following example is drawn from a Microsoft SQL Server use case but applies to most Progress DataDirect drivers.
private void run(String[] args) {
   Connection con = null;
   PreparedStatement prepStmt = null;
   String sql = null;
   try {
      // Create the connection and enable statement pooling
      Class.forName("com.ddtek.jdbc.sqlserver.SQLServerDriver");
      con = DriverManager.getConnection(
         "jdbc:datadirect:sqlserver://SMITH:1440;" +
"RegisterStatementPoolMonitorMBean=true",
         "maxPooledStatements=10",
"test", "test");
      // Prepare a couple of statements
      sql = "INSERT INTO employees (id, name) VALUES(?, ?)";
      prepStmt = con.prepareStatement(sql);
      prepStmt.close();
      sql = "SELECT name FROM employees WHERE id = ?";
      prepStmt = con.prepareStatement(sql);
      prepStmt.close();
      ExtStatementPoolMonitor monitor =
         ((ExtConnection) con).getStatementPoolMonitor();
      System.out.println("Statement Pool - " + monitor.getName());
      System.out.println("Max Size:    " + monitor.getMaxSize());
      System.out.println("Current Size: " + monitor.getCurrentSize());
      System.out.println("Hit Count:    " + monitor.getHitCount());
      System.out.println("Miss Count:   " + monitor.getMissCount());
      System.out.println("Statements:");
      ArrayList statements = monitor.poolEntries(-1, -1, -1);
      Iterator itr = statements.iterator();
      while (itr.hasNext()) {
         String entry = (String)itr.next();
         System.out.println(entry);
      }
}   
catch (Throwable except) {
   System.out.println("ERROR: " + except);
   }
   finally {
      if (con != null) {
         try {
            con.close();
         }
         catch (SQLException except) {}
         }
      }
   }
In the previous code example, the PoolEntries() method returns all statements in the statement pool regardless of statement type, result set cursor type, and concurrency type by specifying the value -1 for each parameter as shown in the following code:
ArrayList statements = monitor.poolEntries(-1, -1, -1);
We could have easily filtered the list of statements to return only prepared statements that have a forward-only result set with a concurrency type of updateable using the following code:
ArrayList statements = monitor.poolEntries(
   ExtStatementPoolMonitor.TYPE_PREPARED_STATEMENT,
   ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);