Index: trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDescriptive.java
===================================================================
--- trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDescriptive.java	(revision 8742)
+++ trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDescriptive.java	(revision 9874)
@@ -8,4 +8,5 @@
 
 import java.sql.SQLException;
+import java.sql.Statement;
 import java.sql.ResultSet;
 
@@ -275,5 +276,5 @@
 	    } else {
 		// TODO: raise an error!
-		System.out.println("Error: METSDescriiptive: unrecognised tag "+childName);
+		System.out.println("Error: METSDescriptive: unrecognised tag "+childName);
 	    }
 	}
@@ -375,13 +376,10 @@
 	select.setWhere(where);
 	
-	connection.execute(select.toString());
-	
 	try {
+	    Statement statement = connection.createStatement();
+	    ResultSet resultSet = statement.executeQuery(select.toString());
 	    GS3SQLAction action;
 	    
-	    ResultSet resultSet = connection.getResultSet();
-	    
-	    if (resultSet != null &&
-		resultSet.first()) {
+	    if (resultSet.first()) {
 		// the node already exists - no need to do anything as such
 		GS3SQLUpdate update = new GS3SQLUpdate("metadata");
@@ -389,14 +387,11 @@
 		action = update;
 	    }
-	    else
-		{ // Set result set to null, just in case next() didn't work above...
-		    resultSet = null;
-		    
-		    // It is a new node and needs writing
-		    action = new GS3SQLInsert("metadata");
-		    
-		    action.addValue("DocID", document.getID().toString());
-		    action.addValue("MetaID", this.ID);
-		}
+	    else { // Set result set to null, just in case first() didn't work above...
+		// It is a new node and needs writing
+		action = new GS3SQLInsert("metadata");
+		
+		action.addValue("DocID", document.getID().toString());
+		action.addValue("MetaID", this.ID);
+	    }
 	    
 	    // always set the group identifier
@@ -404,22 +399,23 @@
 	    
 	    // execute the action as required
-	    connection.execute(action.toString());
-	    
-	    // create a new resultset if necessary
-	    if (resultSet == null) {
-		// now execute the select statement again to get the new identifier
-		// 'MetadataRef'
-		// System.out.println(select.toString());
-		connection.execute(select.toString());
-		
-		resultSet = connection.getResultSet();
-		resultSet.first();
-	    }
-	    
-	    // get the reference for this item...
-	    sqlId = resultSet.getInt("MetadataRef");
+	    statement.execute(action.toString());
+	    
+	    // get the resultSet again
+	    // now execute the select statement again to get the new identifier
+	    // 'MetadataRef'
+	    // System.out.println(select.toString());
+	    resultSet = statement.executeQuery(select.toString());
+	    
+	    if (resultSet.first()) {
+		// get the reference for this item...
+		sqlId = resultSet.getInt("MetadataRef");
+	    }
+	    statement.close();
 	}
 	catch (SQLException sql){
-	    System.out.println(sql);
+	    System.err.println("METSDescriptive.writeSQL(): "+sql);
+	}
+	if (sqlId == -1) {
+	    return false;
 	}
 	
@@ -471,10 +467,9 @@
 	    select.setWhere(where);
 	    
-	    connection.execute(select.toString());
-	    
-	    // parse through the namespaces, calling the namespace class to create instances
-	    // as it will
-	    ResultSet namespaceSet = connection.getResultSet();
-	    if (namespaceSet != null && namespaceSet.first()) {
+	    Statement statement = connection.createStatement();
+	    ResultSet namespaceSet = statement.executeQuery(select.toString());
+	    
+	    // parse through the namespaces, calling the namespace class to create instances as it will
+	    if (namespaceSet.first()) {
 		do {
 		    METSNamespace namespace = METSNamespace.readSQL(connection, namespaceSet);
@@ -483,14 +478,14 @@
 		    }
 		    else {
-			System.out.println("Null namespace output");
+			System.err.println("Null namespace output");
 		    }
 		}
 		while (namespaceSet.next());
 	    }
-	    
+	    statement.close();
 	    return descriptive;
 	}
 	catch (SQLException sqlEx){
-	    System.out.println(sqlEx);
+	    System.err.println("METSDescriptive.readSQL(): "+sqlEx);
 	    System.exit(1);
 	}
