The below Code will Insert the CLOB or BLOB objects in Oracle DB using QTP.
Sample Code:
'CLOB or BLOB file Path
strClobFileName = "C:\Jay\SampleInputs\BLOBorCLOB.txt"
'Connection String
strOracleConnectionString = "Driver= {Microsoft ODBC for Oracle}; " &_
"ConnectString=(DESCRIPTION=" &_
"(ADDRESS=(PROTOCOL=TCP)" &_
"(HOST=hostName) (PORT=1234))" &_
"(CONNECT_DATA=(SERVICE_NAME=ABCD)));uid=userName; pwd=Password;"
'Create Required Objects
Set objCon = CreateObject("Adodb.Connection")
Set objRs = CreateObject("Adodb.Recordset")
Set objCom = CreateObject("Adodb.Command")
Set objStream = CreateObject("ADODB.Stream")
'Set the CursorLocation to Get the Record Count properly
objCon.CursorLocation = 3
'Open the Connection
objCon.Open strOracleConnectionString
'Set the required types for Stream Object
objStream.Charset = "us-ascii"
Const adTypeText = 2
objStream.Type = adTypeText
'Open the Stream Object
objStream.Open
'Load the CLOB or BLOB object from the File
objStream.LoadFromFile strClobFileName
'Command to Execute
'Here we should place the "?" for CLOB or BLOB object to
objCom.CommandText = "INSERT INTO TABLE(BLOBorCLOBColumnName,Col2,Col3) VALUES (?,1,2,)"
'set the Active Connection to ADODB Command
objCom.ActiveConnection = objCon
'Execute the Command with CLOB or BLOB object as Input as objStream.ReadText
set objrs1 = objCom.Execute(strMsg,objStream.ReadText,adExecuteNoRecords)
'Read the strMsg to validate wether Record is inserted or not
If strMsg >= 1 Then
Print "Pass"
Else
Print "Fail"
End If
Sample Code:
'CLOB or BLOB file Path
strClobFileName = "C:\Jay\SampleInputs\BLOBorCLOB.txt"
'Connection String
strOracleConnectionString = "Driver= {Microsoft ODBC for Oracle}; " &_
"ConnectString=(DESCRIPTION=" &_
"(ADDRESS=(PROTOCOL=TCP)" &_
"(HOST=hostName) (PORT=1234))" &_
"(CONNECT_DATA=(SERVICE_NAME=ABCD)));uid=userName; pwd=Password;"
'Create Required Objects
Set objCon = CreateObject("Adodb.Connection")
Set objRs = CreateObject("Adodb.Recordset")
Set objCom = CreateObject("Adodb.Command")
Set objStream = CreateObject("ADODB.Stream")
'Set the CursorLocation to Get the Record Count properly
objCon.CursorLocation = 3
'Open the Connection
objCon.Open strOracleConnectionString
'Set the required types for Stream Object
objStream.Charset = "us-ascii"
Const adTypeText = 2
objStream.Type = adTypeText
'Open the Stream Object
objStream.Open
'Load the CLOB or BLOB object from the File
objStream.LoadFromFile strClobFileName
'Command to Execute
'Here we should place the "?" for CLOB or BLOB object to
objCom.CommandText = "INSERT INTO TABLE(BLOBorCLOBColumnName,Col2,Col3) VALUES (?,1,2,)"
'set the Active Connection to ADODB Command
objCom.ActiveConnection = objCon
'Execute the Command with CLOB or BLOB object as Input as objStream.ReadText
set objrs1 = objCom.Execute(strMsg,objStream.ReadText,adExecuteNoRecords)
'Read the strMsg to validate wether Record is inserted or not
If strMsg >= 1 Then
Print "Pass"
Else
Print "Fail"
End If
Comments