Index: src/edu/ucsb/nceas/metacat/DBQuery.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DBQuery.java	(revision 2445)
+++ src/edu/ucsb/nceas/metacat/DBQuery.java	(revision 2446)
@@ -625,7 +625,7 @@
                             .getOption("xml_returnfield_count")))
                             .intValue();
 
-     // set enterRecords to true if usage_count is more than the offset 
+     // set enterRecords to true if usage_count is more than the offset
      // specified in metacat.properties
      if(usage_count > count){
          enterRecords = true;
@@ -682,17 +682,21 @@
          key = (String) keys.nextElement();
          element = (String)partOfDoclist.get(key);
 
-	 // check if the enterRecords is true, elements is not null, element's 
-         // length is less than the limit of table column and if the document 
+	 // check if the enterRecords is true, elements is not null, element's
+         // length is less than the limit of table column and if the document
          // has been indexed already
-         if(enterRecords && element != null 
+         if(enterRecords && element != null
 		&& element.length() < offset
 		&& element.compareTo((String) partOfDoclistBackup.get(key)) != 0){
              query = "INSERT INTO xml_queryresult (returnfield_id, docid, "
-                 + "queryresult_string) VALUES ('" + returnfield_id
-                 + "', '" + key + "', '" + element + "')";
+                 + "queryresult_string) VALUES (?, ?, ?)";
+
              PreparedStatement pstmt = null;
              pstmt = dbconn.prepareStatement(query);
+             pstmt.setInt(1, returnfield_id);
+             pstmt.setString(2, key);
+             pstmt.setString(3, element);
+
              dbconn.increaseUsageCount(1);
              pstmt.execute();
              pstmt.close();
@@ -809,13 +813,14 @@
        String returnfield = qspec.getSortedReturnFieldString();
 
        // query for finding the id from xml_returnfield
-       String query = "select returnfield_id, usage_count from xml_returnfield "
-           + "where returnfield_string like '" + returnfield +"'";
+       String query = "SELECT returnfield_id, usage_count FROM xml_returnfield "
+            + "WHERE returnfield_string LIKE ?";
        MetaCatUtil.debugMessage("ReturnField Query:" + query, 50);
 
        try {
            // prepare and run the query
            pstmt = dbconn.prepareStatement(query);
+           pstmt.setString(1,returnfield);
            dbconn.increaseUsageCount(1);
            pstmt.execute();
            rs = pstmt.getResultSet();
@@ -846,19 +851,21 @@
 
                // insert a new record
                query = "INSERT INTO xml_returnfield (returnfield_string, usage_count)"
-                   + "VALUES ('" + returnfield + "', '1')";
+                   + "VALUES (?, '1')";
                MetaCatUtil.debugMessage("ReturnField Table Insert:"+ query, 50);
                pstmt = dbconn.prepareStatement(query);
+               pstmt.setString(1, returnfield);
                dbconn.increaseUsageCount(1);
                pstmt.execute();
                pstmt.close();
 
                // get the id of the new record
-               query = "select returnfield_id from xml_returnfield "
-                   + "where returnfield_string like '" + returnfield +"'";
-               MetaCatUtil.debugMessage("ReturnField query after Insert:"
-                                        + query, 50);
+               query = "SELECT returnfield_id FROM xml_returnfield "
+                   + "WHERE returnfield_string LIKE ?";
+               MetaCatUtil.debugMessage("ReturnField query after Insert:" + query, 50);
                pstmt = dbconn.prepareStatement(query);
+               pstmt.setString(1, returnfield);
+
                dbconn.increaseUsageCount(1);
                pstmt.execute();
                rs = pstmt.getResultSet();
@@ -1189,15 +1196,15 @@
      */
     private Vector getElements(Vector parentidList)
     {
-        Vector enum = new Vector();
+        Vector enumVector = new Vector();
         Vector tempVector = null;
 
         for (int count = 0; count < parentidList.size(); count++) {
             tempVector = (Vector) parentidList.get(count);
 
-            enum.add(tempVector.get(1));
+            enumVector.add(tempVector.get(1));
         }
-        return enum;
+        return enumVector;
     }
 
     /*
