Merge remote branch 'origin/pr/1240/head' into merge_1240
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ExtractLobMessage.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ExtractLobMessage.java
index 6c54ff6..8a6c15c 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ExtractLobMessage.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ExtractLobMessage.java
@@ -27,9 +27,9 @@
 
 	static final short LOB_EXTRACT_LEN                 = 0;
 	static final short LOB_EXTRACT_BUFFER              = LOB_EXTRACT_LEN + 1;
-	static final short LOB_EXTRACT_BOTH_LEN_AND_BUFFER = LOB_EXTRACT_BUFFER + 1;
+	static final short LOB_CLOSE_CURSOR                = LOB_EXTRACT_BUFFER + 1;
 
-	static LogicalByteArray marshal(short extractType, String lobHandle, int lobHandleCharset, long lobLength, InterfaceConnection ic) throws SQLException{
+	static LogicalByteArray marshal(short extractType, String lobHandle, int lobHandleCharset, long extractLen, InterfaceConnection ic) throws SQLException{
 		int wlength = Header.sizeOf();
 		LogicalByteArray buf;
 
@@ -37,20 +37,23 @@
 			byte[] lobHandleBytes = ic.encodeString(lobHandle, InterfaceUtilities.SQLCHARSETCODE_UTF8);
 
 			wlength += TRANSPORT.size_int;
-			// wlength += TRANSPORT.size_long; // length of lobHandle
 
 			if (lobHandle.length() > 0) {
 				wlength += TRANSPORT.size_bytesWithCharset(lobHandleBytes);
 			}
 
-			if (lobLength > 0) {
+			if (extractLen > 0) {
 				wlength += TRANSPORT.size_long;
 			}
 
 			buf = new LogicalByteArray(wlength, Header.sizeOf(), ic.getByteSwap());
 
-			buf.insertInt(extractType);
+			buf.insertShort(extractType);
 			buf.insertStringWithCharset(lobHandleBytes, lobHandleCharset);
+			
+			if (extractType == LOB_EXTRACT_BUFFER) {
+				buf.insertLong(extractLen);
+			}
 			return buf;
 		} catch (Exception e) {
 			throw TrafT4Messages.createSQLException(ic.t4props_, ic.getLocale(), "unsupported_encoding", "UTF-8");
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ExtractLobReply.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ExtractLobReply.java
index ca2c7f2..c54d854 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ExtractLobReply.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ExtractLobReply.java
@@ -30,9 +30,11 @@
 	odbc_SQLSvc_ExtractLob_exc_ m_p1;
 	String proxySyntax = "";
 
-	int lobDataLen = 0;
+	long lobLength = 0;
+	long extractLen = 0;
+	byte[] extractData = null;
 
-	byte[] lobDataValue = null;
+	public short extractAPIType = 0;
 
 	ExtractLobReply(LogicalByteArray buf, InterfaceConnection ic) throws SQLException {
 		buf.setLocation(Header.sizeOf());
@@ -42,9 +44,20 @@
 		m_p1.extractFromByteArray(buf, ic);
 
 		if (m_p1.exception_nr == TRANSPORT.CEE_SUCCESS) {
-			lobDataLen = (int) buf.extractInt();
-			if (lobDataLen > 0) {
-				lobDataValue = buf.extractByteArray(lobDataLen);
+
+			extractAPIType = buf.extractShort();
+			switch (extractAPIType) {
+			case 0:
+				lobLength = buf.extractLong();
+				break;
+			case 1:
+				extractLen = buf.extractLong();
+				extractData = buf.extractByteArray(extractLen);
+				break;
+			case 2:
+				break;
+			default:
+				break;
 			}
 		}
 		}
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Properties.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Properties.java
index 917cf45..202bc27 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Properties.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Properties.java
@@ -119,7 +119,9 @@
 	String clobTableName_;
 	String blobTableName_;
 
-	// private short transportBufferSize_;
+    private int lobChunkSize_ = 10; // default 10M
+
+    // private short transportBufferSize_;
 	private boolean useArrayBinding_;
 	private boolean batchRecovery_;
 	private final String propPrefix_ = "t4jdbc.";
@@ -425,6 +427,8 @@
 		setKeepAlive(getProperty("keepAlive"));
 		setTokenAuth(getProperty("tokenAuth"));
         setTcpNoDelay(getProperty("tcpNoDelay"));
+
+        setLobChunkSize(getProperty("lobChunkSize"));
 	}
 
 	T4Properties getT4Properties() {
@@ -518,6 +522,8 @@
 		props.setProperty("tokenAuth", String.valueOf(_tokenAuth));
         props.setProperty("tcpNoDelay", String.valueOf(_tcpNoDelay));
         
+        props.setProperty("lobChunkSize", String.valueOf(lobChunkSize_));
+
 		return props;
 	}
 
@@ -1884,6 +1890,26 @@
 		return reserveDataLocator_;
 	}
 
+    public int getLobChunkSize() {
+        return lobChunkSize_;
+    }
+
+    public void setLobChunkSize(int lobChunkSize_) {
+        this.lobChunkSize_ = lobChunkSize_;
+    }
+
+    public void setLobChunkSize(String val) {
+        this.lobChunkSize_ = 10;
+        if (val != null) {
+            try {
+                this.lobChunkSize_ = Integer.parseInt(val);
+            } catch (NumberFormatException ex) {
+                sqlExceptionMessage_ = "Incorrect value for setLobChunkSize set: " + val + ex.getMessage();
+                this.lobChunkSize_ = 10;
+            }
+        }
+    }
+
 	/**
 	 * Returns the rounding mode set for the driver as an Integer value with one
 	 * of the following values. static int ROUND_CEILING Rounding mode to round
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Blob.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Blob.java
index 499dd82..fb76ea5 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Blob.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Blob.java
@@ -35,13 +35,11 @@
 		super(connection, lobHandle, data, Types.BLOB);
 	}
 
-	@Override
 	public InputStream getBinaryStream() throws SQLException {
 		testAvailability();
 		return new ByteArrayInputStream((byte[]) data_);
 	}
 
-	@Override
 	public InputStream getBinaryStream(long pos, long length) throws SQLException {
 		testAvailability();
 		return new ByteArrayInputStream((byte[]) data_);
@@ -53,7 +51,6 @@
 	 * bytes starting at position pos.
 	 *  */
 
-	@Override
 	public byte[] getBytes(long pos, int length) throws SQLException {
 		testAvailability();
 
@@ -75,14 +72,12 @@
 		return buf;
 	}
 
-	@Override
 	public int setBytes(long pos, byte[] bytes) throws SQLException {
 		testAvailability();
 
 		return setBytes(pos, bytes, 0, bytes.length);
 	}
 
-	@Override
 	public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException {
 		testAvailability();
 		OutputStream out = setBinaryStream(pos);
@@ -102,24 +97,20 @@
 		return len;
 	}
 
-	@Override
 	public long position(Blob pattern, long start) throws SQLException {
 		return position(pattern.getBytes(0, (int) pattern.length()), start);
 	}
 
-	@Override
 	public long position(byte[] pattern, long start) throws SQLException {
 		TrafT4Messages.throwUnsupportedFeatureException(connection_.props_, connection_.getLocale(), "position()");
 		return 0;
 	}
 
-	@Override
 	public OutputStream setBinaryStream(long pos) throws SQLException {
 		testAvailability();
 		return setOutputStream(pos);
 	}
 
-	@Override
 	public void truncate(long len) throws SQLException {
 		testAvailability();
 
@@ -145,13 +136,11 @@
 	}
 
 
-	@Override
 	public long length() throws SQLException {
 		testAvailability();
 		return data_ == null ? 0 : ((byte[]) data_).length;
 	}
 
-	@Override
 	public void free() throws SQLException {
 		data_ = null;
 		isFreed_ = true;
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Clob.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Clob.java
index f7280fe..5877089 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Clob.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Clob.java
@@ -42,13 +42,11 @@
 			this.data_ = "";
 	}
 
-	@Override
 	public void free() throws SQLException {
 		data_ = null;
 		isFreed_ = true;
 	}
 
-	@Override
 	public InputStream getAsciiStream() throws SQLException {
 		testAvailability();
 		if (data_ != null) {
@@ -58,7 +56,6 @@
 		return null;
 	}
 
-	@Override
 	public Reader getCharacterStream() throws SQLException {
 		testAvailability();
 
@@ -69,14 +66,12 @@
 		return null;
 	}
 
-	@Override
 	public Reader getCharacterStream(long pos, long length) throws SQLException {
 		testAvailability();
 
 		return new StringReader(getSubString(pos, (int) length));
 	}
 
-	@Override
 	public String getSubString(long pos, int length) throws SQLException {
 		testAvailability();
 
@@ -94,7 +89,6 @@
 		return ((String) data_).substring(beginIndex, endIndex);
 	}
 
-	@Override
 	public long length() throws SQLException {
 		testAvailability();
 		if (data_ != null) {
@@ -104,7 +98,6 @@
 		return 0;
 	}
 
-	@Override
 	public long position(String searchstr, long start) throws SQLException {
 		testAvailability();
 		//start--;
@@ -123,12 +116,10 @@
 		return pos;
 	}
 
-	@Override
 	public long position(Clob searchstr, long start) throws SQLException {
 		return position(searchstr.getSubString(1L, (int) searchstr.length()), start);
 	}
 
-	@Override
 	public OutputStream setAsciiStream(long pos) throws SQLException {
 		testAvailability();
 		if (pos < 1) {
@@ -139,14 +130,12 @@
 		return setOutputStream(pos);
 	}
 
-	@Override
 	public Writer setCharacterStream(long pos) throws SQLException {
 		testAvailability();
 		TrafT4Writer writer = new TrafT4Writer(this, pos);
 		return writer;
 	}
 
-	@Override
 	public int setString(long pos, String str) throws SQLException {
 		testAvailability();
 		int startIndex = (int) pos - 1;
@@ -168,7 +157,6 @@
 		return len;
 	}
 
-	@Override
 	public int setString(long pos, String str, int offset, int len) throws SQLException {
 		testAvailability();
 		int start = (int) pos - 1;
@@ -183,7 +171,6 @@
 		return len;
 	}
 
-	@Override
 	public void truncate(long len) throws SQLException {
 		testAvailability();
 		if (len > ((String) data_).length()) {
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Lob.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Lob.java
index 054da20..0643173 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Lob.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Lob.java
@@ -34,6 +34,7 @@
 	protected TrafT4Connection connection_ = null;
 	protected boolean isFreed_ = true;
 	protected int lobType = Types.BLOB;
+	protected long length = 0;
 
 	protected Object data_ = null;
 
@@ -91,23 +92,49 @@
 		}
 
 		T4Connection t4connection = this.connection_.getServerHandle().getT4Connection();
-		LogicalByteArray wbuffer = ExtractLobMessage.marshal(ExtractLobMessage.LOB_EXTRACT_BUFFER, lobHandle_, 1, 0,
+		LogicalByteArray wbuffer = ExtractLobMessage.marshal(ExtractLobMessage.LOB_EXTRACT_LEN, lobHandle_, 1, 0,
 				connection_.ic_);
 
 		LogicalByteArray rbuffer = t4connection.getReadBuffer(TRANSPORT.SRVR_API_EXTRACTLOB, wbuffer);
 		ExtractLobReply reply = new ExtractLobReply(rbuffer, connection_.ic_);
-		data_ = reply.lobDataValue;
+		length = reply.lobLength;
+
+		byte[] fetchData_ = new byte[(int) length];
+
+		try {
+			int pos = 0;
+            int chunkSize = connection_.props_.getLobChunkSize() * 1024 * 1024;
+			while (pos < length) {
+				int remainSize = (int) (length - pos);
+				int fecthSize = remainSize < chunkSize ? remainSize : chunkSize;
+				wbuffer =  ExtractLobMessage.marshal(ExtractLobMessage.LOB_EXTRACT_BUFFER, lobHandle_, 1, fecthSize, connection_.ic_);
+				rbuffer = t4connection.getReadBuffer(TRANSPORT.SRVR_API_EXTRACTLOB, wbuffer);
+				reply = new ExtractLobReply(rbuffer, connection_.ic_);
+				System.arraycopy(reply.extractData, 0, fetchData_, pos, (int) reply.extractLen);
+				pos += reply.extractLen;
+			}
+
+		}
+		catch(SQLException se) {
+			throw se;
+		}
+		finally {
+			// close the LOB cursor
+			wbuffer = ExtractLobMessage.marshal(ExtractLobMessage.LOB_CLOSE_CURSOR, lobHandle_, 1, 0, connection_.ic_);
+			rbuffer = t4connection.getReadBuffer(TRANSPORT.SRVR_API_EXTRACTLOB, wbuffer);
+			reply = new ExtractLobReply(rbuffer, connection_.ic_);
+		}
 		switch (lobType) {
 		case Types.BLOB:
-			data_ = reply.lobDataValue;
+			data_ = fetchData_;
 			break;
 		case Types.CLOB:
 			try {
-			    if (reply.lobDataLen == 0) {
+			    if (length == 0) {
 			        data_ = "";
 			    }
 			    else {
-			        data_ = new String(reply.lobDataValue, "UTF-8");
+			        data_ = new String(fetchData_, "UTF-8");
 			    }
 			} catch (UnsupportedEncodingException e) {
 				throw TrafT4Messages.createSQLException(this.connection_.ic_.t4props_, this.connection_.ic_.getLocale(),
@@ -126,7 +153,7 @@
 		    return ;
 		T4Connection t4connection = this.connection_.getServerHandle().getT4Connection();
 
-		final long chunkSize = 100 * 1024 * 1024;
+        final long chunkSize = connection_.props_.getLobChunkSize() * 1024 * 1024;
 		LogicalByteArray wbuffer = null;
 
 		byte[] valueBuffer = null;
diff --git a/core/conn/odbc/src/odbc/nsksrvr/Interface/marshalingsrvr_srvr.cpp b/core/conn/odbc/src/odbc/nsksrvr/Interface/marshalingsrvr_srvr.cpp
index 63dfbb7..30b70ba 100644
--- a/core/conn/odbc/src/odbc/nsksrvr/Interface/marshalingsrvr_srvr.cpp
+++ b/core/conn/odbc/src/odbc/nsksrvr/Interface/marshalingsrvr_srvr.cpp
@@ -2307,8 +2307,10 @@
       , char* &buffer
       , UInt32& message_length
       , const struct odbc_SQLsrvr_ExtractLob_exc_ *exception_
-      , IDL_long_long lobDataLen
-      , BYTE * lobDataValue
+      , IDL_short extractLobAPI
+      , IDL_long_long lobLength
+      , IDL_long_long extractLen
+      , BYTE * extractData
 )
 {
     CEE_status sts = CEE_SUCCESS;
@@ -2352,13 +2354,20 @@
             break;
     }
 
-    // length of IDL_long  LOB len
-    wlength += sizeof(IDL_long);
-    if (lobDataValue != NULL)
-    {
-        wlength += lobDataLen;
+    wlength += sizeof(IDL_short);
+    switch (extractLobAPI) {
+    case 0:
+        wlength += sizeof(IDL_long_long);
+        break;
+    case 1:
+        wlength += sizeof(IDL_long_long);
+        wlength += extractLen;
+        break;
+    case 2:
+        break;
+    default:
+        break;
     }
-    wlength += lobDataLen;
 
     // update the length of message
     message_length = wlength;
@@ -2394,10 +2403,25 @@
         default:
             break;
     }
-    IDL_long_copy((IDL_long *)&lobDataLen, curptr);
-    if (lobDataValue != NULL)
-    {
-        IDL_byteArray_copy(lobDataValue, lobDataLen, curptr);
+
+    //IDL_long_copy((IDL_long *)&extractLobAPI, curptr);
+    IDL_short_copy((IDL_short *)&extractLobAPI, curptr);
+
+    switch (extractLobAPI) {
+    case 0:
+        IDL_long_long_copy((IDL_long_long *)&lobLength, curptr);
+        break;
+    case 1:
+        IDL_long_long_copy((IDL_long_long *)&extractLen, curptr);
+        if (extractLen != 0)
+        {
+            IDL_byteArray_copy(extractData, extractLen, curptr);
+        }
+        break;
+    case 2:
+        break;
+    default:
+        break;
     }
 
     return sts;
diff --git a/core/conn/odbc/src/odbc/nsksrvr/Interface/marshalingsrvr_srvr.h b/core/conn/odbc/src/odbc/nsksrvr/Interface/marshalingsrvr_srvr.h
index 8d21291..af3e6ae 100644
--- a/core/conn/odbc/src/odbc/nsksrvr/Interface/marshalingsrvr_srvr.h
+++ b/core/conn/odbc/src/odbc/nsksrvr/Interface/marshalingsrvr_srvr.h
@@ -388,8 +388,10 @@
                 , char *&buffer
                 , UInt32 & message_length
                 , const struct odbc_SQLsrvr_ExtractLob_exc_ *exception_
-                , IDL_long_long lobDataLen
-                , BYTE * lobDataValue
+                , IDL_short extractLobAPI
+                , IDL_long_long lobLength
+                , IDL_long_long extractLen
+                , BYTE * extractData
 );
 
 CEE_status
diff --git a/core/conn/odbc/src/odbc/nsksrvr/Interface/odbcs_srvr.cpp b/core/conn/odbc/src/odbc/nsksrvr/Interface/odbcs_srvr.cpp
index 5fba9e1..a6f6639 100644
--- a/core/conn/odbc/src/odbc/nsksrvr/Interface/odbcs_srvr.cpp
+++ b/core/conn/odbc/src/odbc/nsksrvr/Interface/odbcs_srvr.cpp
@@ -1526,14 +1526,15 @@
     IDL_char     *curptr;
     IDL_long inputPosition = 0;
 
-    IDL_long extractLobAPI = 0;
+    IDL_short extractLobAPI = 0;
+    IDL_long extractLen = 0;
     IDL_long lobHandleLen = 0;
     IDL_string lobHandle = NULL;
     IDL_long lobHandleCharset = 0;
 
     curptr = pnode->r_buffer();
 
-    extractLobAPI = *(IDL_long *)(curptr + inputPosition);
+    extractLobAPI = *(IDL_short *)(curptr + inputPosition);
     inputPosition += sizeof(extractLobAPI);
 
     lobHandleLen = *(IDL_long*)(curptr + inputPosition);
@@ -1547,11 +1548,15 @@
         inputPosition += sizeof(lobHandleCharset);
     }
 
+    extractLen = *(IDL_long *)(curptr + inputPosition);
+    inputPosition += sizeof(extractLen);
+
     odbc_SQLSrvr_ExtractLob_ame_(
             objtag_,
             call_id_,
             extractLobAPI,
-            lobHandle
+            lobHandle,
+            extractLen
             );
 }
 
diff --git a/core/conn/odbc/src/odbc/nsksrvr/Interface/odbcs_srvr_res.cpp b/core/conn/odbc/src/odbc/nsksrvr/Interface/odbcs_srvr_res.cpp
index 48602b7..5a34c2c 100644
--- a/core/conn/odbc/src/odbc/nsksrvr/Interface/odbcs_srvr_res.cpp
+++ b/core/conn/odbc/src/odbc/nsksrvr/Interface/odbcs_srvr_res.cpp
@@ -647,8 +647,10 @@
     /* In   */ CEE_tag_def    objtag_
   , /* In   */ const CEE_handle_def *call_id_
   , /* In   */ const struct odbc_SQLsrvr_ExtractLob_exc_ *exception_
-  , /* In   */ IDL_long_long  lobDataLen
-  , /* In   */ BYTE       *lobDataValue
+  , /* In   */ IDL_short extractLobAPI
+  , /* In   */ IDL_long_long  lobLength
+  , /* In   */ IDL_long_long  extractLen
+  , /* In   */ BYTE   *  extractData
   )
 {
     CInterface* pnode = (CInterface *)objtag_;
@@ -666,17 +668,19 @@
             , buffer
             , message_length
             , exception_
-            , lobDataLen
-            , lobDataValue
+            , extractLobAPI
+            , lobLength
+            , extractLen
+            , extractData
             );
 
     if (sts == CEE_SUCCESS)
         sts = pnode->send_response(buffer, message_length, call_id_);
 
-    if (lobDataValue != NULL)
+    if (extractData != NULL)
     {
-        delete [] lobDataValue;
-        lobDataValue = NULL;
+        delete [] extractData;
+        extractData = NULL;
     }
     return sts;
 }
diff --git a/core/conn/odbc/src/odbc/nsksrvr/Interface/odbcs_srvr_res.h b/core/conn/odbc/src/odbc/nsksrvr/Interface/odbcs_srvr_res.h
index fba2e39..7e5f51d 100644
--- a/core/conn/odbc/src/odbc/nsksrvr/Interface/odbcs_srvr_res.h
+++ b/core/conn/odbc/src/odbc/nsksrvr/Interface/odbcs_srvr_res.h
@@ -346,8 +346,10 @@
     /* In    */ CEE_tag_def objtag_
   , /* In    */ const CEE_handle_def *call_id_
   , /* In    */ const struct odbc_SQLsrvr_ExtractLob_exc_ *exception_
-  , /* In    */ IDL_long_long lobDataLen
-  , /* In    */ BYTE * lobDataValue
+  , /* In   */ IDL_short  extractLobAPI
+  , /* In   */ IDL_long_long  lobLength
+  , /* In   */ IDL_long_long  extractLen
+  , /* In   */ BYTE   *  extractData
 );
 
 void
diff --git a/core/conn/odbc/src/odbc/nsksrvr/SrvrConnect.cpp b/core/conn/odbc/src/odbc/nsksrvr/SrvrConnect.cpp
index 39f363e..fb623e2 100644
--- a/core/conn/odbc/src/odbc/nsksrvr/SrvrConnect.cpp
+++ b/core/conn/odbc/src/odbc/nsksrvr/SrvrConnect.cpp
@@ -8534,12 +8534,13 @@
 odbc_SQLSrvr_ExtractLob_ame_(
     /* In   */ CEE_tag_def objtag_
   , /* In   */ const CEE_handle_def *call_id_
-  , /* In   */ IDL_long    extractLobAPI
-  , /* In   */ IDL_string  lobHandle)
+  , /* In   */ IDL_short   extractLobAPI
+  , /* In   */ IDL_string  lobHandle
+  , /* In   */ IDL_long_long    extractLen)
 {
     ERROR_DESC_LIST_def sqlWarning = {0, 0};
-    IDL_long_long lobDataLen = 0;
-    BYTE * lobDataValue = NULL;
+    IDL_long_long lobLength = 0;
+    BYTE * extractData = NULL;
 
     odbc_SQLsrvr_ExtractLob_exc_ exception_ = {0, 0};
 
@@ -8548,14 +8549,17 @@
                                  &exception_,
                                  extractLobAPI,
                                  lobHandle,
-                                 lobDataLen,
-                                 lobDataValue);
+                                 lobLength,
+                                 extractLen,
+                                 extractData);
 
     odbc_SQLSrvr_ExtractLob_ts_res_(objtag_,
                                     call_id_,
                                     &exception_,
-                                    lobDataLen,
-                                    lobDataValue);
+                                    extractLobAPI,
+                                    lobLength,
+                                    extractLen,
+                                    extractData);
 }
 
 void
diff --git a/core/conn/odbc/src/odbc/nsksrvr/SrvrConnect.h b/core/conn/odbc/src/odbc/nsksrvr/SrvrConnect.h
index 66556e8..d429fc8 100644
--- a/core/conn/odbc/src/odbc/nsksrvr/SrvrConnect.h
+++ b/core/conn/odbc/src/odbc/nsksrvr/SrvrConnect.h
@@ -336,8 +336,9 @@
 odbc_SQLSrvr_ExtractLob_ame_(
     /* In   */ CEE_tag_def objtag_
   , /* In   */ const CEE_handle_def *call_id_
-  , /* In   */ IDL_long    extractLobAPI
+  , /* In   */ IDL_short    extractLobAPI
   , /* In   */ IDL_string  lobHandle
+  , /* In   */ IDL_long_long   extractLen
   );
 
 void
diff --git a/core/conn/odbc/src/odbc/nsksrvrcore/srvrcommon.h b/core/conn/odbc/src/odbc/nsksrvrcore/srvrcommon.h
index 6ed6692..ec5315c 100644
--- a/core/conn/odbc/src/odbc/nsksrvrcore/srvrcommon.h
+++ b/core/conn/odbc/src/odbc/nsksrvrcore/srvrcommon.h
@@ -387,8 +387,9 @@
   , /* In    */ odbc_SQLsrvr_ExtractLob_exc_ *exception_
   , /* In    */ IDL_long extractLobAPI
   , /* In    */ IDL_string lobHandle
-  , /* In    */ IDL_long_long &lobDataLen
-  , /* In    */ BYTE* &lobDataValue);
+  , /* In    */ IDL_long_long &lobLength
+  , /* Out   */ IDL_long_long &extractLen
+  , /* Out   */ BYTE *& extractData);
 
 extern "C" void
 odbc_SQLSrvr_UpdateLob_sme_(
diff --git a/core/conn/odbc/src/odbc/nsksrvrcore/srvrothers.cpp b/core/conn/odbc/src/odbc/nsksrvrcore/srvrothers.cpp
index ccbb689..a6e3c2b 100644
--- a/core/conn/odbc/src/odbc/nsksrvrcore/srvrothers.cpp
+++ b/core/conn/odbc/src/odbc/nsksrvrcore/srvrothers.cpp
@@ -6388,13 +6388,14 @@
     /* In    */ CEE_tag_def objtag_
   , /* In    */ const CEE_handle_def *call_id_
   , /* Out   */ odbc_SQLsrvr_ExtractLob_exc_ *exception_
-  , /* In    */ IDL_long extractLobAPI
+  , /* In    */ IDL_short extractLobAPI
   , /* In    */ IDL_string lobHandle
-  , /* Out   */ IDL_long_long &lobDataLen
-  , /* Out   */ BYTE *& lobDataValue
+  , /* In    */ IDL_long_long &lobLength
+  , /* Out   */ IDL_long_long &extractLen
+  , /* Out   */ BYTE *& extractData
   )
 {
-    char LobExtractQuery[1000];
+    char LobExtractQuery[1000] = {0};
     char RequestError[200] = {0};
     SRVR_STMT_HDL  *QryLobExtractSrvrStmt = NULL;
 
@@ -6411,8 +6412,29 @@
         exception_->exception_nr = odbc_SQLsrvr_ExtractLob_ParamError_exn_;
         exception_->u.ParamError.ParamDesc = SQLSVC_EXCEPTION_UNABLE_TO_ALLOCATE_SQL_STMT;
     }
+    switch (extractLobAPI) {
+    case 0:
+        extractData = NULL;
+        snprintf(LobExtractQuery, sizeof(LobExtractQuery), "EXTRACT LOBLENGTH(LOB'%s') LOCATION %Ld", lobHandle, (Int64)&lobLength);
+        break;
+    case 1:
+        extractData = new BYTE[extractLen + 1];
+        if (extractData == NULL)
+        {
+            exception_->exception_nr = odbc_SQLsrvr_ExtractLob_ParamError_exn_;
+            exception_->u.ParamError.ParamDesc = SQLSVC_EXCEPTION_BUFFER_ALLOC_FAILED;
+        }
 
-    snprintf(LobExtractQuery, sizeof(LobExtractQuery), "EXTRACT LOBLENGTH(LOB'%s') LOCATION %Ld", lobHandle, (Int64)&lobDataLen);
+        snprintf(LobExtractQuery, sizeof(LobExtractQuery), "EXTRACT LOBTOBUFFER(LOB'%s', LOCATION %Ld, SIZE %Ld)", lobHandle, (Int64)extractData, &extractLen);
+        break;
+    case 102:
+        extractLen = 0;
+        extractData = NULL;
+        snprintf(LobExtractQuery, sizeof(LobExtractQuery), "EXTRACT LOBTOBUFFER(LOB'%s', LOCATION %Ld, SIZE %Ld)", lobHandle, (Int64)extractData, &extractLen);
+        break;
+    default:
+        return ;
+    }
 
     try
     {
@@ -6446,70 +6468,13 @@
                 ODBCMX_SERVER,
                 srvrGlobal->srvrObjRef,
                 1,
+                    //"Exception in executing EXTRACT LOBTOBUFFER");
                 "Exception in executing EXTRACT LOBLENGTH");
 
         exception_->exception_nr = odbc_SQLsrvr_ExtractLob_ParamError_exn_;
         exception_->u.ParamError.ParamDesc = SQLSVC_EXCEPTION_EXECDIRECT_FAILED;
     }
 
-    lobDataValue = new BYTE[lobDataLen + 1];
-    if (lobDataValue == NULL)
-    {
-        exception_->exception_nr = odbc_SQLsrvr_ExtractLob_ParamError_exn_;
-        exception_->u.ParamError.ParamDesc = SQLSVC_EXCEPTION_BUFFER_ALLOC_FAILED;
-    }
-
-    memset(lobDataValue, 0, lobDataLen + 1);
-
-    memset(LobExtractQuery, 0, sizeof(LobExtractQuery));
-
-    snprintf(LobExtractQuery, sizeof(LobExtractQuery), "EXTRACT LOBTOBUFFER(LOB'%s', LOCATION %Ld, SIZE %Ld)", lobHandle, (Int64)lobDataValue, &lobDataLen);
-
-    if (exception_->exception_nr == 0)
-    {
-        try
-        {
-            short retcode = QryLobExtractSrvrStmt->ExecDirect(NULL, LobExtractQuery, EXTERNAL_STMT, TYPE_CALL, SQL_ASYNC_ENABLE_OFF, 0);
-            if (retcode == SQL_ERROR)
-            {
-                ERROR_DESC_def *p_buffer = QryLobExtractSrvrStmt->sqlError.errorList._buffer;
-                strncpy(RequestError, p_buffer->errorText, sizeof(RequestError) - 1);
-
-                SendEventMsg(MSG_SQL_ERROR,
-                        EVENTLOG_ERROR_TYPE,
-                        srvrGlobal->nskProcessInfo.processId,
-                         ODBCMX_SERVER,
-                         srvrGlobal->srvrObjRef,
-                         2,
-                         p_buffer->sqlcode,
-                         RequestError);
-
-                exception_->exception_nr = odbc_SQLsrvr_ExtractLob_ParamError_exn_;
-                exception_->u.SQLError.errorList._length = QryLobExtractSrvrStmt->sqlError.errorList._length;
-                exception_->u.SQLError.errorList._buffer = QryLobExtractSrvrStmt->sqlError.errorList._buffer;
-                exception_->u.ParamError.ParamDesc = SQLSVC_EXCEPTION_EXECUTE_FAILED;
-            }
-        }
-        catch (...)
-        {
-            SendEventMsg(MSG_PROGRAMMING_ERROR,
-                    EVENTLOG_ERROR_TYPE,
-                    srvrGlobal->nskProcessInfo.processId,
-                    ODBCMX_SERVER,
-                    srvrGlobal->srvrObjRef,
-                    1,
-                    "Exception in executing EXTRACT LOBTOBUFFER");
-
-            exception_->exception_nr = odbc_SQLsrvr_ExtractLob_ParamError_exn_;
-            exception_->u.ParamError.ParamDesc = SQLSVC_EXCEPTION_EXECDIRECT_FAILED;
-        }
-
-        if (exception_->exception_nr != 0) {
-            lobDataLen = 0;
-            delete [] lobDataValue;
-            lobDataValue = NULL;
-        }
-    }
 }
 
 extern "C" void
@@ -6591,6 +6556,9 @@
         exception_->u.ParamError.ParamDesc = SQLSVC_EXCEPTION_EXECUTE_FAILED;
     }
 
+    if (QryLobUpdateSrvrStmt != NULL) {
+        QryLobUpdateSrvrStmt->Close(SQL_DROP);
+    }
 }
 
 //========================================================================
diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/JdbcCommon.java b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/JdbcCommon.java
index 6ab5fca..ec68443 100644
--- a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/JdbcCommon.java
+++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/JdbcCommon.java
@@ -117,8 +117,11 @@
         StringBuilder buf = new StringBuilder(ddl);
         ddl = buf.toString();
 
-        try {
-            _conn.createStatement().execute(ddl);
+        try (
+            Statement stmt = _conn.createStatement();
+        )
+        {
+            stmt.execute(ddl);
         } catch (Exception e) { 
             System.out.println(e.getMessage());
             fail("Failed to create table");
@@ -154,8 +157,11 @@
         if (commConn == null)
             commConn = getConnection();
 
-        try {
-            commConn.createStatement().execute("create schema " + _catalog + "." + _schema);
+        try (
+            Statement stmt = commConn.createStatement();
+        )
+        {
+            stmt.execute("create schema " + _catalog + "." + _schema);
         } catch (Exception e) {
             // Do nothing, the schema may already exist.
         }
@@ -165,8 +171,11 @@
         if (commConn == null)
             commConn = getConnection();
 
-        try {
-            commConn.createStatement().execute("drop schema " + _catalog + "." + _schema + " cascade");
+        try (
+            Statement stmt = commConn.createStatement();
+        )
+        {
+            stmt.execute("drop schema " + _catalog + "." + _schema + " cascade");
         } catch (Exception e) {
             // Do nothing, the schema may not exist.  
         }
@@ -184,8 +193,10 @@
 
         for (String objname : objDropList) {
             for (int i = 0; i < 3; i++) {
-                try {
-                    commConn.createStatement().executeUpdate("drop " + objname + " cascade");
+                try (
+                    Statement stmt = commConn.createStatement();
+                ){
+                    stmt.executeUpdate("drop " + objname + " cascade");
                     break; // no execption, break out here
                 } catch (Exception e) {
                     String msg = e.getMessage();
diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/PropTest.java b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/PropTest.java
index a4a269e..47bd5ca 100644
--- a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/PropTest.java
+++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/PropTest.java
@@ -41,6 +41,7 @@
 import org.junit.Test;
 import static org.junit.Assert.*;
 
+import static org.junit.Assert.fail;
 
 /*  The test case is added for bug #1452993;
  *  T2 don't read the property file from System Properties but T4 do it.
@@ -54,10 +55,14 @@
     public void  testDefaultPropertiesConnection() throws SQLException {
         Connection conn = null;
         try {
+            conn = Utils.getUserConnection();
+        }
+        catch (Exception e) {
+            fail("failed to create connection" + e.getMessage());
+        }
+        try {
             // The option -Dproperties=propFile can be used to instead of System.setProperty()
             System.setProperty("properties", System.getProperty("trafjdbc.properties"));
-
-            conn = DriverManager.getConnection(Utils.url, Utils.usr, Utils.pwd);
             System.out.println("Catalog : " + conn.getCatalog());
             assertEquals("Catalog should be the same as the properties file defined",Utils.catalog, conn.getCatalog());
             System.out.println("testDefaultPropertiesConnection : PASS");
diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestBlob.java b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestBlob.java
index ff7c398..283555c 100644
--- a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestBlob.java
+++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestBlob.java
@@ -22,6 +22,7 @@
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -38,7 +39,8 @@
 
 public class TestBlob {
     private static final String tableName = "BLOBTEST";
-    private static final String strCreateTable = "CREATE TABLE " + Utils.schema + "." + tableName + "(C1 int, c2 BLOB);";
+    private static final String strCreateTable = "CREATE TABLE if not exists " + Utils.schema + "." + tableName
+            + "(C1 int, c2 BLOB);";
     private static final String strDropTable = "DROP TABLE " + Utils.schema + "." + tableName;
 
     private static Connection _conn = null;
@@ -46,15 +48,19 @@
     @BeforeClass
     public static void doTestSuiteSetup() throws Exception {
         try {
-            _conn = DriverManager.getConnection(Utils.url, Utils.usr, Utils.pwd);
+            _conn = Utils.getUserConnection();
+        }
+        catch (Exception e) {
+            fail("failed to create connection" + e.getMessage());
+        }
+        try (
             Statement stmt = _conn.createStatement();
-
+        ) {
             // use CQD to enable BLOB support
             stmt.execute("CQD TRAF_BLOB_AS_VARCHAR 'OFF'");
             stmt.execute(strCreateTable);
         } catch (Exception e) {
-            System.out.println(e.getMessage());
-            e.printStackTrace();
+            fail("failed to set CQDs for Blob : " + e.getMessage());
         }
     }
 
diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestBlobBatch.java b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestBlobBatch.java
index b3acb5e..ee7f44c 100644
--- a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestBlobBatch.java
+++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestBlobBatch.java
@@ -23,6 +23,7 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
@@ -165,15 +166,18 @@
     @BeforeClass
     public static void doTestSuiteSetup() throws Exception {
         try {
-            _conn = DriverManager.getConnection(Utils.url, Utils.usr, Utils.pwd);
+            _conn = Utils.getUserConnection();
+        } catch (Exception e) {
+            fail("failed to create connection" + e.getMessage());
+        }
+        try (
             Statement stmt = _conn.createStatement();
-
+        ) {
             // use CQD to enable BLOB support
             stmt.execute("CQD TRAF_BLOB_AS_VARCHAR 'OFF'");
             stmt.execute(strCreateTable);
         } catch (Exception e) {
-            System.out.println(e.getMessage());
-            e.printStackTrace();
+            fail("failed to set CQD : " + e.getMessage());
         }
     }
     
diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestClob.java b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestClob.java
index 51a7cf5..1919c53 100644
--- a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestClob.java
+++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestClob.java
@@ -23,6 +23,7 @@
 import static org.junit.Assert.assertEquals;

 import static org.junit.Assert.assertFalse;

 import static org.junit.Assert.assertTrue;

+import static org.junit.Assert.fail;

 

 import java.io.IOException;

 import java.io.InputStream;

@@ -51,10 +52,17 @@
 

 	@BeforeClass

 	public static void doTestSuiteSetup() throws Exception {

-		try {

-			_conn = DriverManager.getConnection(Utils.url, Utils.usr, Utils.pwd);

-			Statement stmt = _conn.createStatement();

-

+	    try {

+            _conn = Utils.getUserConnection();

+	    }

+	    catch (SQLException se) {

+            se.printStackTrace();

+	        fail("failed to create connection : " + se.getMessage());

+	    }

+	    try (

+	            Statement stmt = _conn.createStatement();

+	            )

+        {

 			// use CQD to enable CLOB support

 			stmt.execute("CQD TRAF_CLOB_AS_VARCHAR 'OFF'");

 			// stmt.execute(strDropTable);

@@ -62,6 +70,7 @@
 		} catch (Exception e) {

 			System.out.println(e.getMessage());

 			e.printStackTrace();

+            fail("failed to set CQD for CLOB");

 		}

 	}

 

diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestClobBatch.java b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestClobBatch.java
index d729dbe..b5ea1d0 100644
--- a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestClobBatch.java
+++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestClobBatch.java
@@ -22,6 +22,7 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.Reader;
 import java.io.StringReader;
@@ -200,16 +201,20 @@
 
 	@BeforeClass
 	public static void doTestSuiteSetup() throws Exception {
-		try {
-			_conn = DriverManager.getConnection(Utils.url, Utils.usr, Utils.pwd);
-			Statement stmt = _conn.createStatement();
+        try {
+            _conn = Utils.getUserConnection();
+        } catch (Exception e) {
+            fail("failed to create connection" + e.getMessage());
+        }
 
+        try (
+			Statement stmt = _conn.createStatement();
+        ) {
 			// use CQD to enable BLOB support
 			stmt.execute("CQD TRAF_CLOB_AS_VARCHAR 'OFF'");
 			stmt.execute(strCreateTable);
 		} catch (Exception e) {
-			System.out.println(e.getMessage());
-			e.printStackTrace();
+            fail("failed to set CQD : " + e.getMessage());
 		}
 	}
 
diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestForeignKey.java b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestForeignKey.java
index d6c2175..90c19c4 100644
--- a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestForeignKey.java
+++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestForeignKey.java
@@ -26,8 +26,6 @@
 import java.sql.ResultSet;

 import java.sql.Statement;

 

-import javax.swing.text.Utilities;

-

 import org.junit.AfterClass;

 import org.junit.BeforeClass;

 import org.junit.Test;

@@ -46,22 +44,26 @@
 	private static final String FK21 = "FK21";

 	private static final String FK22 = "FK22";

 

-	private static final String strCreatePKTABLE1Query = "CREATE TABLE " + Utils.schema + "." + PKTABLE1 + "( "

+    private static final String strCreatePKTABLE1Query = "CREATE TABLE IF NOT EXISTS " + Utils.schema + "." + PKTABLE1

+            + "( "

 			+ PK1 + " INT NOT NULL PRIMARY KEY)";

 	private static final String strDropPKTABLE1Query = "DROP TABLE " + Utils.schema + "." + PKTABLE1;

 

-	private static final String strCreatePKTABLE2Query = "CREATE TABLE " + Utils.schema + "." + PKTABLE2 + "( "

+    private static final String strCreatePKTABLE2Query = "CREATE TABLE IF NOT EXISTS " + Utils.schema + "." + PKTABLE2

+            + "( "

 			+ PK2 + " INT NOT NULL PRIMARY KEY)";

 	private static final String strDropPKTABLE2Query = "DROP TABLE " + Utils.schema + "." + PKTABLE2;

 

-	private static final String strCreateFKTABLE1Query = "CREATE TABLE " + Utils.schema + "." + FKTABLE1 + "( "

+    private static final String strCreateFKTABLE1Query = "CREATE TABLE IF NOT EXISTS " + Utils.schema + "." + FKTABLE1

+            + "( "

 			+ FK1 + " INT NOT NULL, "

 			+ FK2 + " INT NOT NULL, "

 			+ "FOREIGN KEY (" + FK1 + ") REFERENCES " + Utils.schema + "." + PKTABLE1 + "(" + PK1 + "), "

 			+ "FOREIGN KEY (" + FK2 + ") REFERENCES " + Utils.schema + "." + PKTABLE2 + "(" + PK2 + "))";

 	private static final String strDropFKTABLE1Query = "DROP TABLE " + Utils.schema + "." + FKTABLE1;

 

-	private static final String strCreateFKTABLE2Query = "CREATE TABLE " + Utils.schema + "." + FKTABLE2 + "( "

+    private static final String strCreateFKTABLE2Query = "CREATE TABLE IF NOT EXISTS " + Utils.schema + "." + FKTABLE2

+            + "( "

 			+ FK21 + " INT NOT NULL, "

 			+ FK22 + " INT NOT NULL, "

 			+ "FOREIGN KEY (" + FK21 + ") REFERENCES " + Utils.schema + "." + PKTABLE1 + "(" + PK1 + "), "

@@ -69,21 +71,23 @@
 	private static final String strDropFKTABLE2Query = "DROP TABLE " + Utils.schema + "." + FKTABLE2;

 

 	private static Connection _conn;

-	

+

 	@BeforeClass

 	public static void doTestSuiteSetup() throws Exception {

-		try{

-			_conn = DriverManager.getConnection(Utils.url, Utils.usr, Utils.pwd);

-			Statement stmt = _conn.createStatement();

-			

-			stmt.execute(strCreatePKTABLE1Query);

-			stmt.execute(strCreatePKTABLE2Query);

-			stmt.execute(strCreateFKTABLE1Query);

-			stmt.execute(strCreateFKTABLE2Query);

-		}

+        try {

+            _conn = Utils.getUserConnection();

+        } catch (Exception e) {

+            fail("failed to create connection" + e.getMessage());

+        }

+

+        try (Statement stmt = _conn.createStatement();) {

+            stmt.execute(strCreatePKTABLE1Query);

+            stmt.execute(strCreatePKTABLE2Query);

+            stmt.execute(strCreateFKTABLE1Query);

+            stmt.execute(strCreateFKTABLE2Query);

+        }

 		catch (Exception e) {

-			System.out.println(e.getMessage());

-			e.printStackTrace();

+            fail("failed to create table: " + e.getMessage());

 		}

 	}

 	

@@ -96,12 +100,19 @@
 		

 		try {

 			DatabaseMetaData metaData = _conn.getMetaData();

-			ResultSet rs = metaData.getImportedKeys("TRAFODION", Utils.schema, FKTABLE1);

 			int rowNum = 0;

-			while(rs.next()) {

-				compareForeignkeyWithExp("testGetImportedKeys", rowNum + 1, rs, expFkInfo[rowNum]);

-				rowNum += 1;

-			}

+            try (

+                 ResultSet rs = metaData.getImportedKeys("TRAFODION", Utils.schema, FKTABLE1);

+            )

+            {

+                while(rs.next()) {

+                    compareForeignkeyWithExp("testGetImportedKeys", rowNum + 1, rs, expFkInfo[rowNum]);

+                    rowNum += 1;

+                }

+            }

+            catch (Exception e) {

+                fail(e.getMessage());

+            }

 			assertEquals(rowNum, 2);

 		} catch (Exception e) {

 			e.printStackTrace();

@@ -117,12 +128,16 @@
 		

 		try {

 			DatabaseMetaData metaData = _conn.getMetaData();

-			ResultSet rs = metaData.getExportedKeys("TRAFODION", Utils.schema, PKTABLE1);

-			int rowNum = 0;

-			while(rs.next()) {

-				compareForeignkeyWithExp("testGetExportedKeys", rowNum + 1, rs, expFkInfo[rowNum]);

-				rowNum += 1;

-			}

+            int rowNum = 0;

+            try (

+			    ResultSet rs = metaData.getExportedKeys("TRAFODION", Utils.schema, PKTABLE1);

+            )

+            {

+			    while(rs.next()) {

+			    	compareForeignkeyWithExp("testGetExportedKeys", rowNum + 1, rs, expFkInfo[rowNum]);

+			    	rowNum += 1;

+			    }

+            }

 			assertEquals(rowNum, 2);

 		} catch (Exception e) {

 			e.printStackTrace();

@@ -137,12 +152,16 @@
 		

 		try {

 			DatabaseMetaData metaData = _conn.getMetaData();

-			ResultSet rs = metaData.getCrossReference("TRAFODION", Utils.schema, PKTABLE1, "TRAFODION", Utils.schema, FKTABLE1);

 			int rowNum = 0;

-			while(rs.next()) {

-				compareForeignkeyWithExp("testGetCrossReference", rowNum + 1, rs, expFkInfo[rowNum]);

-				rowNum += 1;

-			}

+            try (

+			    ResultSet rs = metaData.getCrossReference("TRAFODION", Utils.schema, PKTABLE1, "TRAFODION", Utils.schema, FKTABLE1);

+            )

+            {

+			    while(rs.next()) {

+			    	compareForeignkeyWithExp("testGetCrossReference", rowNum + 1, rs, expFkInfo[rowNum]);

+			    	rowNum += 1;

+			    }

+            }

 			assertEquals(rowNum, 1);

 		} catch (Exception e) {

 			e.printStackTrace();

diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestGetIndexInfo.java b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestGetIndexInfo.java
index 1cab0b0..9789ced 100644
--- a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestGetIndexInfo.java
+++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestGetIndexInfo.java
@@ -47,12 +47,23 @@
 

 	@BeforeClass

     public static void doTestSuiteSetup() throws Exception {

-    	try {

-    		_conn = DriverManager.getConnection(Utils.url, Utils.usr, Utils.pwd);

+        try {

+            _conn = Utils.getUserConnection();

+        } catch (Exception e) {

+            fail("failed to create connection" + e.getMessage());

+        }

+

+        try (Statement stmt = _conn.createStatement()

+        ) {

+            stmt.execute(strCreateTableQuery);

+        }

+        catch (Exception e) {

+            fail("failed to create the table : " + e.getMessage());

+        }

+        try (

     		Statement stmt = _conn.createStatement();

-    		stmt.execute(strCreateTableQuery);

-    		

-    		PreparedStatement pstmt = _conn.prepareStatement(strInsertQuery);

+                PreparedStatement pstmt = _conn.prepareStatement(strInsertQuery);

+        ) {

     		int[][] testValues = {

     				{1, 2},

     				{10, 3},

@@ -65,8 +76,7 @@
     			pstmt.addBatch();

     		}

     		pstmt.executeBatch();

-    		pstmt.close();

-    		

+

     		// create index

     		stmt.execute(strCreateIndexQuery);