Index: branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/GS3SQLConnection.java
===================================================================
--- branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/GS3SQLConnection.java	(revision 9845)
+++ branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/GS3SQLConnection.java	(revision 9847)
@@ -14,7 +14,7 @@
 {
 
-    public GS3SQLConnection(java.sql.Connection connection)
+    public GS3SQLConnection(java.sql.Connection connection, String database)
     { 
-	super(connection);
+	super(connection, database);
     }
     
@@ -25,5 +25,8 @@
   }
     
-
+    public GS3SQLConnection cloneConnection() {
+	GS3SQLConnection conn = GS3SQLConnectionFactory.getGS3SQLConnection(this.database);
+	return conn;
+    }
   /**
    *  Initialise a collection for use.
@@ -224,4 +227,5 @@
       statement.execute(classData.toString());
 
+      statement.close();
       //
       // END OF GSDL TABLES
@@ -232,4 +236,10 @@
     {
       System.out.println(ex.toString());
+      if (statement != null) {
+	  try {
+	      statement.close();
+	  } catch (Exception e){}
+	  statement = null;
+      }
       return false;
     }
Index: branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/GS3SQLConnectionFactory.java
===================================================================
--- branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/GS3SQLConnectionFactory.java	(revision 9845)
+++ branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/GS3SQLConnectionFactory.java	(revision 9847)
@@ -32,5 +32,5 @@
 	    return null;
 	}
-	return new SQLConnection(c);
+	return new SQLConnection(c, database);
     }
 
@@ -42,5 +42,5 @@
 	    return null;
 	}
-	return new GS3SQLConnection(c);
+	return new GS3SQLConnection(c, database);
     }
 
Index: branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/SQLConnection.java
===================================================================
--- branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/SQLConnection.java	(revision 9845)
+++ branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/SQLConnection.java	(revision 9847)
@@ -11,9 +11,10 @@
     protected Connection connection;
     protected Statement  statement;
-
-
-    public SQLConnection(java.sql.Connection connection)
+    protected String database;
+    
+    public SQLConnection(java.sql.Connection connection, String database)
     { 
 	this.connection = connection;
+	this.database = database;
     }
     
@@ -21,14 +22,28 @@
 	if (this.connection!=null) {
 	    try {
-		this.connection.close();
+		this.connection.close();		
 	    } catch (Exception e) {}
-	    
-	    this.connection = null;
 	}
+	if (this.statement!=null) {
+	    try {
+		this.statement.close();		
+	    } catch (Exception e) {}
+	}
+	
+	this.connection = null;   
+	this.statement = null;
+
     }
     
+    public void close() {
+	finalize();
+    }
+	
     public boolean execute(String sql)
     {
 	try {
+	    if (this.statement != null) {
+		this.statement.close();
+	    }
 	    this.statement = this.connection.createStatement();
 	    this.statement.execute(sql);
@@ -41,4 +56,12 @@
     }
     
+    public void closeStatement() {
+	try {
+	    if (this.statement != null) {
+		this.statement.close();
+	    } 
+	} catch (Exception e) {}
+	    
+    }
     public Statement createStatement()
     { 
@@ -67,8 +90,14 @@
     
     public boolean connectToDatabase(String database) {
+	if (this.connection != null) {
+	    try {
+		this.connection.close();
+	    } catch (Exception e) {}
+	}
 	this.connection = GS3SQLConnectionFactory.getConnection(database);
 	if (this.connection == null) {
 	    return false;
 	}
+	this.database = database;
 	return true;
     }
@@ -78,4 +107,5 @@
 	    this.statement = this.connection.createStatement();
 	    this.statement.execute("DROP DATABASE "+database+";");
+	    this.statement.close();
 	}
 	catch (SQLException ex){
@@ -92,4 +122,5 @@
 	    this.statement = this.connection.createStatement();
 	    this.statement.execute(command);
+	    this.statement.close();
 	} catch (Exception e) {
 	    System.err.println(e);
