Index: trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentList.java
===================================================================
--- trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentList.java	(revision 8861)
+++ trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentList.java	(revision 9874)
@@ -13,4 +13,5 @@
 
 import java.sql.SQLException;
+import java.sql.Statement;
 import java.sql.ResultSet;
 
@@ -68,19 +69,18 @@
     select.setWhere(where);
 
-    this.connection.execute(select.toString());
-
-    ResultSet results = this.connection.getResultSet();
-    if (results != null) {
-      select = new GS3SQLSelect("filegroups");
-      select.addField("DocID");
-      select.setDistinct(true);
-      
-      where = new GS3SQLWhere();
-      where.setCondition(GS3SQLWhere.OR_CONDITION);
-
-      GS3SQLWhereItem whereItem = null;
-
-      try {
-	results.first();
+    try {
+	Statement statement = connection.createStatement();
+	ResultSet results = statement.executeQuery(select.toString());
+    
+	select = new GS3SQLSelect("filegroups");
+	select.addField("DocID");
+	select.setDistinct(true);
+      
+	where = new GS3SQLWhere();
+	where.setCondition(GS3SQLWhere.OR_CONDITION);
+	
+	GS3SQLWhereItem whereItem = null;
+
+      	results.first();
 	do {
 	  int fileGroupRef = results.getInt("FileGroupRef");
@@ -90,9 +90,7 @@
 	while (results.next());
 	select.setWhere(where);
-	results.close();
-	
-	this.connection.execute(select.toString());
-	
-	results = this.connection.getResultSet();
+	
+	results = statement.executeQuery(select.toString());
+	
 	results.first();
 	do {
@@ -100,9 +98,10 @@
 	  reply.add(docId);
 	} while (results.next());
-      } 
-      catch (SQLException sqlEx)
-      { System.err.println(sqlEx);
-      }
-    }
+	statement.close();
+    }
+    catch (SQLException sqlEx) {
+	System.err.println("DocumentList.getDocumentIdsWithFile(): "+sqlEx);
+    }
+    
     return reply;
   }
@@ -173,14 +172,15 @@
   }
 
-  private List findDocumentIdsUsingFileQuery(String query)
-  { this.connection.execute(query);
-
-    try {
-
-      ResultSet results = this.connection.getResultSet();
-      if (results == null ||
-	  !results.first()) {
-	return null;
-      }
+    private List findDocumentIdsUsingFileQuery(String query) {
+    
+	try {
+	
+	Statement statement = connection.createStatement();
+	ResultSet results = statement.executeQuery(query);
+
+	if (!results.first()) {
+	    statement.close();
+	    return null;
+	}
       
       // get a list of group ids first and turn it into a query on filegroups
@@ -207,9 +207,9 @@
       // structures...recreating new filegroup queries as necessary
       while (queryBuffer.length() > 0) {
-	connection.execute(queryBuffer.toString());
-	
-	results = this.connection.getResultSet();
-	if (results == null || !results.first()) {
-	  return null;
+	results = statement.executeQuery(queryBuffer.toString());
+	
+	if (!results.first()) {
+	    statement.close();
+	    return null;
 	}
 	
@@ -256,10 +256,9 @@
       
       // execute the division query
-      this.connection.execute(queryBuffer.toString());
-      
-      results = this.connection.getResultSet();
-      if (results == null ||
-	  !results.first()) {
-	return null;
+      results = statement.executeQuery(queryBuffer.toString());
+      
+      if (!results.first()) {
+	  statement.close();
+	  return null;
       }
 
@@ -268,9 +267,10 @@
 	reply.add(results.getString("DocID"));
       } while (results.next());
-
+      
+      statement.close();
       return reply;
     }
     catch (SQLException ex) {
-      System.err.println(ex);
+      System.err.println("DocumentList.findDocumentIdsUsingFileQuery()"+ ex);
     }
     return null;
@@ -454,20 +454,19 @@
     select.addField("*");
     
-    ResultSet documents;
     try {
-      connection.execute(select.toString());
-      documents = connection.getResultSet();
-
-      if (documents.first())
-      { do
-	{ DocumentInterface document = AbstractDocument.readSQL(connection, documents);
-          list.addDocument(document);
-	}
-	while (documents.next());
-      }
-    }
-    catch (java.sql.SQLException ex)
-    { System.out.println(ex);
-      return null;
+	Statement statement = connection.createStatement();
+	ResultSet documents = statement.executeQuery(select.toString());
+	if (documents.first()) { 
+	    do {
+		DocumentInterface document = AbstractDocument.readSQL(connection, documents);
+		list.addDocument(document);
+	    }
+	    while (documents.next());
+	}
+	statement.close();
+    }
+    catch (java.sql.SQLException ex) {
+	System.out.println("DocumentList.writeSQLDocuments(): "+ex);
+	return null;
     }
 
@@ -487,4 +486,5 @@
 {
   private boolean hasNext;
+  private Statement statement;
   private ResultSet resultSet;
   private GS3SQLConnection connection;
@@ -498,8 +498,9 @@
 
     try {
-      connection.execute(select.toString());
-      this.resultSet = connection.getResultSet();
+	this.statement = connection.createStatement();
+      this.resultSet = statement.executeQuery(select.toString());
       this.hasNext = this.resultSet.first();
     } catch (SQLException ex) {
+      System.err.println("DocumentListIterator(): "+ex);
       this.hasNext = false;
     }
@@ -520,7 +521,8 @@
 
       if (!this.hasNext) {
-	this.resultSet.close(); // be a good citizen & close used result sets
+	  this.statement.close(); // be a good citizen & close used statement 
       }
     } catch (SQLException ex) {
+	System.err.println("DocumentList.iterator.next(): "+ex);
       this.hasNext = false;
     }
