Tuesday, November 29, 2005

XML Insertions for Oracle XMLType Large Files

private void MethodXX()
{
try
{
string fileName = "File.DAT";
StreamReader objSR = new StreamReader (@"..\\..\\File.DAT");
string completeFile = objSR.ReadToEnd ();
OracleConnection oraCon = new OracleConnection ();
oraCon.ConnectionString = "Data Source=RDCFEED;User Id=SYSMAN;Password=password;Integrated Security=no;";
oraCon.Open ();
OracleCommand oraCmd = new OracleCommand ("spT1", oraCon);
oraCmd.Transaction = oraCmd.Connection.BeginTransaction ();
oraCmd.CommandType = CommandType.StoredProcedure;
oraCmd.Parameters.Add(new OracleParameter("tmpBlob", OracleType.Clob)).Direction = ParameterDirection.Output;
oraCmd.ExecuteNonQuery();
OracleLob tempLob = OracleLob.Null ;
tempLob = (OracleLob )oraCmd.Parameters[0].Value;
byte [] fileInBytes;
Encoding temp = Encoding.Unicode ;
fileInBytes = temp.GetBytes (completeFile);
tempLob.BeginBatch(OracleLobOpenMode.ReadWrite);
tempLob.Write(fileInBytes, 0, fileInBytes.Length);
tempLob.EndBatch();
oraCmd.Parameters.Clear();
oraCmd.CommandText = "spInsertRDCXML";
oraCmd.CommandType = CommandType.StoredProcedure;
OracleParameter paramFileName = new OracleParameter ("File_Name", OracleType.VarChar);
paramFileName.Direction = ParameterDirection.Input ;
paramFileName.Value = fileName;
OracleParameter paramFileContent = new OracleParameter ("File_Content", OracleType.Clob);
paramFileContent.Direction = ParameterDirection.Input ;
paramFileContent.Value = tempLob;
oraCmd.Parameters.Add (paramFileName);
oraCmd.Parameters.Add (paramFileContent);
oraCmd.ExecuteNonQuery ();
oraCmd.Transaction.Commit ();
}
catch(Exception ex)
{
MessageBox.Show (ex.Message );
}
}

0 Comments:

Post a Comment

<< Home