Insert CLOB into oracle under weblogic

Situation: running my servlet under weblogic, want to insert more than 4000 characters into CLOB of oracle 8.1.7
Problem: cannot be done by using code which is able to do it under tomcat
i use this code in tomcat:
import java.sql.*;
import oracle.sql.CLOB;
import oracle.jdbc.driver.OracleResultSet;
con.setAutoCommit(false);
Statement stmt = con.createStatement();
rs = stmt.executeQuery("SELECT clob_field FROM table where rid=id FOR UPDATE");
rs.next();
CLOB clob = ((OracleResultSet)rs).getCLOB(1);
Writer writer = clob.getCharacterOutputStream();
writer.write(dataString);
writer.close()l
con.commit();
con.setAutoCommit(true);
stmt.close();
after that i know that i can't use API of oracle when i'm using weblogic (e.g. oracle.sql.CLOB)
and i find this code from other user:
import weblogic.jdbc.vendor.oracle.OracleThinClob;
import java.io.*;
import java.sql.*;
PreparedStatement stmt = con.prepareStatement ( "INSERT INTO database VALUES ( ?, EMPTY_CLOB() )" );
stmt.setInt ( 1, 1 );
// inserts a new entry with an empty clob object
stmt.executeUpdate ();
if ( stmt != null )
stmt.close();
// retrieves CLOB-Object
stmt = con.prepareStatement ( "SELECT clob_field FROM database WHERE id=?" );
stmt.setInt ( 1, 1 );
ResultSet rs = stmt.executeQuery ( );
if ( rs.next() )
Clob cl = rs.getClob(1);
Writer clobWriter = ((OracleThinClob)cl).getCharacterOutputStream();
// Open the sample file as a stream for insertion into the Clob column
File testFile = new File ( "file.txt" );
FileReader testReader = new FileReader ( testFile );
// buffer to hold data to being written to the clob.
char[] cBuffer = new char[((OracleThinClob)cl).getBufferSize()];
// Read data from file, write it to clob
int iRead = 0;
while( (iRead= testReader.read(cBuffer)) != -1 )
clobWriter.write( cBuffer, 0, iRead);
testReader.close();
clobWriter.close();
if ( rs != null )
rs.close();
if ( stmt != null )
stmt.close();
// update clob-data in database
stmt = con.prepareStatement ( "UPDATE database SET clob_field = ? WHERE id = ?" );
stmt.setClob ( 1, cl );
stmt.setInt ( 2, 1 );
stmt.executeUpdate();
it throws java.lang.ClassCastException: oracle.sql.CLOB
but i haven't imported or used any API from oracle.........
please help
thanks

hi,
unfortunatly, you can't do this with welbogic6.1 because it 'manage' itself oracle librairies (weblogic.jar),
here is the way i solved the pb for BLOB :
i replaced :
BLOB blob = ((OracleResultSet)rs).getBLOB(1);
by
weblogic.jdbc.rmi.SerialOracleBlob cast1 =(weblogic.jdbc.rmi.SerialOracleBlob)rs.getBlob("myBlob");
weblogic.jdbc.rmi.internal.OracleTBlobImpl cast2 =(weblogic.jdbc.rmi.internal.OracleTBlobImpl)cast1.getTheRealBlob();
BLOB myBlob = (oracle.sql.BLOB)cast2.getTheRealBlob();
it is the same for clob (i suppose ^_^)
hope this helps !
Badr.

Similar Messages

  • Insert data into oracle table from XML file

    I need to insert data into oracle table from XML file
    If anybody handled this type of scenario, Please let me know how to insert data into oracle table from XML file
    Thanks in advance

    The XML DB forum provides the best support for XML topics related to Oracle.
    Here's the FAQ on that forum:
    XML DB FAQ
    where there are plenty of examples of shredding XML into Oracle tables and such like. ;)

  • How to insert images into oracle databse......

    hi,
    i have to insert images into oracle database..
    but we have a procedure to insert images into oracle database..
    how to execute procedure.
    my images file is on desktop.
    i am using ubuntu linux 8.04..
    here i am attaching code of my procedure
    create or replace PROCEDURE INSERT_BLOB(filE_namE IN VARCHAR2,dir_name varchar2)
    IS
    tmp number;
    f_lob bfile;
    b_lob blob;
    BEGIN
    dbms_output.put_line('INSERT BLOB Program Starts');
    dbms_output.put_line('--------------------------');
    dbms_output.put_line('File Name :'||filE_namE);
    dbms_output.put_line('--------------------------');
    UPDATE photograph SET image=empty_blob()
    WHERE file_name =filE_namE
    returning image INTO b_lob;
    f_lob := bfilename( 'BIS_IMAGE_WORKSPACE',filE_namE);
    dbms_lob.fileopen(f_lob,dbms_lob.file_readonly);
    --dbms_lob.loadfromfile(b_lob,f_lob,dbms_lob.getlength(f_lob));              
    insert into photograph values (111,user,sysdate,b_lob);
    dbms_lob.fileclose(f_lob);
    dbms_output.put_line('BLOB Successfully Inserted');
    dbms_output.put_line('--------------------------');
    commit;
    dbms_output.put_line('File length is: '||dbms_lob.getlength( f_lob));
    dbms_output.put_line('Loaded length is: '||dbms_lob.getlength(b_lob));
    dbms_output.put_line('BLOB Committed.Program Ends');
    dbms_output.put_line('--------------------------');
    END inserT_bloB;
    warm regerds
    pydiraju
    please solve my problem
    thanks in advance.......

    thank you
    but i am getting the following errors.
    i connected as dba and created directory on /home/pydiraju/Desktop/PHOTO_DIR'
    and i gave all permissions to scott user.
    but it not working . it gives following errors.
    ERROR at line 1:
    ORA-22288: file or LOB operation FILEOPEN failed
    Permission denied
    ORA-06512: at "SYS.DBMS_LOB", line 523
    ORA-06512: at "SCOTT.LOAD_FILE", line 28
    ORA-06512: at line 1
    Warm regards,
    Pydiraju.P
    Mobile: +91 - 9912380544

  • JDBC receiver adapter: Insert of CLOB into Oracle DB

    Hi,
    I've got a short question:
    Is it possible to insert CLOB fields (larger than 4kB) into an Orcale database using the JDBC receiver adapter without using a stored procedure?
    We are on XI 3.0 SP20.
    I had someting in mind that this is only possible with a stored procedure but I am not sure on this.
    Thanks and Regards,
    Helmut

    HI,
    Is it possible to insert CLOB fields (larger than 4kB) into an Orcale database using the JDBC receiver adapter without using a stored procedure?
       yes, you can do it but it is not a best practise, but using Stored Procedure is .
    Regards,
    karna...

  • Inserting unicode into oracle

    Hi every one ,
    I need to know how to insert unicode data(data in other language) into oracle using java can any one give me hint or reference to any page
    I would be thankful .... !
    Regards,
    Ibrahim...!
    Message was edited by:
    Ibrahim_coder

    Firstly, I'm assuming that your database is running in a character set that supports Unicode text. If it's not, forget it. You ain't gonna put a square peg in a round hole. Check your NLS settings to confirm what language your DB is running in.
    Fortunately for you, java also natively supports unicode, which means that you shouldn't have any problems. Providing, that is, that you use unicode character sets throughout your app and don't use any Reader classes that use a binary or latin charset.
    Where is the data that you want to enter coming from? Keyboard? File? Web? If it is the web you will also need to ensure that the web side of your app is set to Unicode encoding.
    Once you have checked that everything runs in unicode mode, you should be able to write unicode data straight to the database, without any other worries. If you need to manually enter unicode characters, you can do it using the unicode escape character ie "\u0000".
    If you come across any other specific problems, post them here and we can try to resolve them - answering vauge generic qs such as this isn't easy.
    If you want to be very sure about the data you are putting into the DB, you could always use RAW or BLOB datatypes in preference to VARCHAR(2) and CLOB datatypes, however you would then have to do all the charset conversion yourself.
    HTH

  • Error While reading CLOB from Oracle using WebLogic Connection Pool, Works fine with out using pool

    PROBLEM DESCRIPTION :
         When I try to read a clob from Oracle, I receive "ORA-03120: two-task
    conversion routine: integer overflow" Error.
         This error occurs only for CLOB Type and only if I try to connect to
    Oracle using WebLogic JDriver/Oracle POOL.
         IMPORTANT NOTE: I can read CLOB or any other data using direct JDBC
    connection to ORacle with out any problem.
         Below Please find the JAVA CODE for Both Working and NON Working .
    Created a Connection Pool as:
    Name: MyJDBCConnectionPool
    URL : jdbc:weblogic:oracle
    DIRVER:weblogic.jdbc.oci.Driver
    NON WORKING JAVA CODE (USES WEBLOGIC JDBC CONNECTION POOL TO ORACLE):
    Driver myDriver =
    (Driver)Class.forName("weblogic.jdbc.pool.Driver").newInstance();
    Connection mconn =
    myDriver.connect("jdbc:weblogic:pool:MyJDBCConnectionPool",null);
    mconn.setAutoCommit (false);
    CallableStatement cs = mconn.prepareCall("{call
    P_XMLTEST2(?)}"); //This returns a CLOB
    cs.registerOutParameter(1,java.sql.Types.CLOB);
    cs.execute();
    Clob clob = null;
    clob = cs.getClob(1);
    String data =new String();
    data = clob.getSubString(1, (int)clob.length());
    System.out.println(data); //print the data
    data = null;
    clob=null;
    cs.close();
    WORKING JAVA CODE (USES DIRECT THIN JDBC CONNECTION TO ORACLE):
    Driver myDriver =
    (Driver)Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    Connection mconn =
    myDriver.connect("jdbc:oracle:thin:@server:1521:DB",null);
    mconn.setAutoCommit (false);
    CallableStatement cs = mconn.prepareCall("{call
    P_XMLTEST2(?)}"); //This returns a CLOB
    cs.registerOutParameter(1,java.sql.Types.CLOB);
    cs.execute();
    Clob clob = null;
    clob = cs.getClob(1);
    String data =new String();
    data = clob.getSubString(1, (int)clob.length());
    System.out.println(data); //print the data
    data = null;
    clob=null;
    cs.close();
    ERROR MESSAGE:
         ORA-03120: two-task conversion routine: integer overflow
    I appreciate your help on this problem.

    PROBLEM DESCRIPTION :
         When I try to read a clob from Oracle, I receive "ORA-03120: two-task
    conversion routine: integer overflow" Error.
         This error occurs only for CLOB Type and only if I try to connect to
    Oracle using WebLogic JDriver/Oracle POOL.
         IMPORTANT NOTE: I can read CLOB or any other data using direct JDBC
    connection to ORacle with out any problem.
         Below Please find the JAVA CODE for Both Working and NON Working .
    Created a Connection Pool as:
    Name: MyJDBCConnectionPool
    URL : jdbc:weblogic:oracle
    DIRVER:weblogic.jdbc.oci.Driver
    NON WORKING JAVA CODE (USES WEBLOGIC JDBC CONNECTION POOL TO ORACLE):
    Driver myDriver =
    (Driver)Class.forName("weblogic.jdbc.pool.Driver").newInstance();
    Connection mconn =
    myDriver.connect("jdbc:weblogic:pool:MyJDBCConnectionPool",null);
    mconn.setAutoCommit (false);
    CallableStatement cs = mconn.prepareCall("{call
    P_XMLTEST2(?)}"); //This returns a CLOB
    cs.registerOutParameter(1,java.sql.Types.CLOB);
    cs.execute();
    Clob clob = null;
    clob = cs.getClob(1);
    String data =new String();
    data = clob.getSubString(1, (int)clob.length());
    System.out.println(data); //print the data
    data = null;
    clob=null;
    cs.close();
    WORKING JAVA CODE (USES DIRECT THIN JDBC CONNECTION TO ORACLE):
    Driver myDriver =
    (Driver)Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    Connection mconn =
    myDriver.connect("jdbc:oracle:thin:@server:1521:DB",null);
    mconn.setAutoCommit (false);
    CallableStatement cs = mconn.prepareCall("{call
    P_XMLTEST2(?)}"); //This returns a CLOB
    cs.registerOutParameter(1,java.sql.Types.CLOB);
    cs.execute();
    Clob clob = null;
    clob = cs.getClob(1);
    String data =new String();
    data = clob.getSubString(1, (int)clob.length());
    System.out.println(data); //print the data
    data = null;
    clob=null;
    cs.close();
    ERROR MESSAGE:
         ORA-03120: two-task conversion routine: integer overflow
    I appreciate your help on this problem.

  • ADF Mobile - insert data into oracle db from oracle adf mobile application

    Hi,
    I have to insert data from mobile into oracle database 11g(not in local sqlite database), can somebody tell me how to do it?
    Thanks,
    Anshul

    Hi, Anshul, one common way is to expose DB data as ADF BC, and then add a service interface on top of ADF BC. This would allow the ADF Mobile app to access server DB through ADF BC. There may be other mechanisms to access server-side DB - I think APEX also expose some REST interface to Oracle DB as well. Another option is to use TopLink - TopLink can also expose some REST services.
    Thanks,
    Joe Huang

  • How to insert data into Oracle db from MySQL db through PHP?

    Hi,
    I want to insert my MySQL data into Oracle database through PHP.
    I can access Mysql database using mysql_conect() & Oracle database using oci_connect() through PHP.
    Now How can I insert my data which is in MySQL into Oracle table. Both table structure are exactly same.
    So I can use
    insert into Oracle_Table(Oracle_columns....) values(Select * from MySQL_Table);
    But again problem is I can't open both connections at the same time.
    So has anyone done this before or anyone having any other idea..
    Plz guide me...

    You can do it if you setup a ODBC Gateway between MYSQL and Oracle DB. Then you can directly read from MySQL table using DB links and insert into Oracle table in one single SQL Statement.
    Otherwise you need to fetch the data from MySQL Into variables in your PHP Program and then insert into Oracle after binding the variables to the insert statement for Oracle. Hope that is clear enough.
    Regards
    Prakash

  • Inserting variables into oracle

    how do you creat insert statements in oracle using variables? it won't accept this statement
    stmt.executeUpdate("INSERT into T_LINKMANAGER(LMID,LMNAME,LMURL,LMFLAG,LMHITS,LMCATEG) VALUES(ct,aname,aurl,'false',0,acat)");
    giving a column not allowed here error

    If you're new to this, you should ESPECIALLY learn to use bind variables.
    There are times when experts know not to use bind variables, but for 90-99% of all SQL, and 99.9% of all inserts, bind variables should be used.
    Bind variables are what grownup developers use. They:
    1) usually make your code run much faster in the long run, most definitely so on Oracle
    2) make your code more secure; search the web for "SQL injection" to see why
    3) often make your code easier to code; you don't have to worry about embedded single-quotes in your data breaking your SQL
    Where I work, when we interview for new Java developers, if they claim any JDBC knowledge at all, we ask them to write a sample. If they don't use bind variables, they drastically reduce their chances of getting the job.
    Back to your original query:
    1) when asking help in a forum it's ALWAYS better to cut and paste the full original error message than to paraphrase it; there are often clues that get omitted in a paraphase
    2) In your SQL:"INSERT into T_LINKMANAGER(LMID,LMNAME,LMURL,LMFLAG,LMHITS,LMCATEG) VALUES(ct,aname,aurl,'false',0,acat)"ct, aname, aurl, and acat are being interpreted as Oracle column names.
    If those are supposed to be literal values, you must write them as 'ct', etc.
    If those are Java String variables that you want to embed in your SQL, you need to do: "INSERT into T_LINKMANAGER(LMID,LMNAME,LMURL,LMFLAG,LMHITS,LMCATEG) VALUES('" +ct+"','" + aname + "','"  ...If there's ever ANY chance that your Java variables will ever have a ' (single-quote) character in them, then before the SQL statement is built, you have to escape the embedded ' (convert ' to '' (single-quote single-quote) ). To avoid this common headache, use bind variables.
    Actually, for heavily used code, building up a String with "+" is also bad; it generates excessive amounts of intermediate values that have to be garbage collected, thereby slowing your throughput. If you just have to use dynamically built SQL (you should use bind variables instead), then you should build the string in a StringBuffer and convert it to a String at execution.

  • Insert data into oracle database using a PHP form

    I'm trying to enter data into my oracle database table using a php form. When I click submit no data is added. Could someone help me please. I'm new to php/oracle thing.
    NOTE: I don't have any problem connecting to the database using php.
    Here is the code I'm using:
    <?php
    // just print form asking for name if none was entered
    if( !isset($query)) {   
    echo "<form action=\"$uri\" method=post>\n";
    echo "<p>Enter Name: ";
    echo "<input type=text size=100 maxlength=200 name=data value=\"$data\">\n";
    echo "<br><input type=submit name=submit value=Submit>\n";
    echo "</form>\n";
    exit;
    // insert client's name
    $query = "INSERT INTO client (name) VALUES ($data)";
    // connect to Oracle
    $username = "xxxx";
    $paswd = "yyyyyy";
    $dbstring = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)".
    "(HOST=patriot.gmu.edu)(PORT=1521))".
    "(CONNECT_DATA=(SID=COSC)))";
    $db_conn = ocilogon($username, $paswd, $dbstring);
    $stmt = OCIParse($db_conn, $query);
    OCIExecute($stmt, OCI_DEFAULT);
    OCIFreeStatement($stmt);
    OCILogoff($db_conn);
    ?>
    Thanks for your help. I will also appreciate a better was to do it.
    Tony

    resumption and jer,
    Sorry I cannot format the code for easy reading!
    The page is submitting to itself. See action = \"$uri\". I used the same logic to enter SELECT querries into the database. It pulls and displays data back on the webpage. The code I used for this is below. Compare it with the one above for inserting data into the table.
    <?php
    // connect to oracle
    $username = "xxxxx";
         $paswd = "yyyyy";
         $dbstring = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)".
              "(HOST=patriot.gmu.edu)(PORT=1521))".
              "(CONNECT_DATA=(SID=COSC)))";
         $db_conn = ocilogon($username, $paswd, $dbstring);
    // username and password will be unset if they weren't passed,
    // or if they were wrong
    if( !isset($query)) {
    // just print form asking for account details
    echo "<form action=\"$uri\" method=post>\n";
    echo "<p>Enter Query: ";
    echo "<input type=text size=100 maxlength=200 name=query value=\"$query\">\n";
    echo "<br><input type=submit name=submit value=Submit>\n";
    echo "</form>\n";
    exit;
    // remove unwanted slashes from the query
    $query = stripslashes($query);
    // run the query
    $stmt = OCIParse($db_conn, $query);
    OCIExecute($stmt, OCI_DEFAULT);
    // Open the HTML table.
    print '<table border="1" cellspacing="0" cellpadding="3">';
    // Read fetched headers.
    print '<tr>';
    for ($i = 1;$i <= ocinumcols($stmt);$i++)
    print '<td class="e">'.ocicolumnname($stmt,$i).'</td>';
    print '</tr>';
    // Read fetched data.
    while (ocifetch($stmt))
    // Print open and close HTML row tags and columns data.
    print '<tr>';
    for ($i = 1;$i <= ocinumcols($stmt);$i++)
    print '<td class="v">'.ociresult($stmt,$i).'</td>';
    print '</tr>';
    // Close the HTML table.
    print '</table>';
    OCIFreeStatement($stmt);
    OCILogoff($db_conn);
    ?>

  • Native SQL: insert data into oracle database, no return message.

    hi,
    the statement : insert into <TableName> values (Source)
    how can I know if the data have already insert to the database table?
    now I have a program have this problem: the data has already exist, but there's no error message return when insert the same data again.
    data: dbs like dbcon-con_name value 'HRGK',
                       dbtype type dbcon_dbms.
    data: sqlerr_ref type ref to cx_sql_exception,
             exc_ref    type ref to cx_sy_native_sql_error,
             error_text type string.
    data: cnt type i,
            i(2) type c.
    set locale language 'E'.
    EXEC SQL.
      CONNECT TO :DBS
    ENDEXEC.
    EXEC SQL.
      SET CONNECTION :DBS
    ENDEXEC.
    EXEC SQL.
      SELECT COUNT(*) from org_unit into :cnt
    ENDEXEC.
    write: / cnt.
    *do.
    i = 'A'.               
    try.
        EXEC SQL.
          BEGIN
           insert into ORG_UNIT ( ORGAN_ID, UNIT_NO, UNIT_NAME, PARENT_ID)
                         values ( 'A', '123412', 'SDFSG', 'DDS');                     " ORGAN_ID is primary key
    " If the data 'A' has already exist in database ORG_UNIT, it will show error message
    " But if I use :I instead 'A', it will not show error message.
            IF SQL%FOUND THEN
               COMMIT;
            END IF;
          END;
        endexec.
        EXEC SQL.
          SELECT COUNT(*) from ORG_UNIT into :cnt
        ENDEXEC.
        write: / cnt.
    catch cx_sy_native_sql_error into exc_ref.
        error_text = exc_ref->get_text( ).
        write: / error_text.
      catch cx_sql_exception into sqlerr_ref.
        perform handle_sql_exception using sqlerr_ref.
    endtry.
    EXEC SQL.
      disconnect :DBS
    ENDEXEC.
    *enddo.
    *&      Form  handle_sql_exception
    form handle_sql_exception
      using p_sqlerr_ref type ref to cx_sql_exception.
      format color col_negative.
      if p_sqlerr_ref->db_error = 'X'.
        write: / 'SQL error occured:', p_sqlerr_ref->sql_code,
               / p_sqlerr_ref->sql_message.                     "#EC NOTEXT
      else.
        write:
          / 'Error from DBI (details in dev-trace):',
            p_sqlerr_ref->internal_error.                       "#EC NOTEXT
      endif.
    endform.                    "handle_sql_exception
    please help to see the words:
    *" If the data 'A' has already exist in database ORG_UNIT, it will show error message*
    *" But if I use :I instead 'A', it will not show error message.*
    in the program.
    Thanks a lot!

    resumption and jer,
    Sorry I cannot format the code for easy reading!
    The page is submitting to itself. See action = \"$uri\". I used the same logic to enter SELECT querries into the database. It pulls and displays data back on the webpage. The code I used for this is below. Compare it with the one above for inserting data into the table.
    <?php
    // connect to oracle
    $username = "xxxxx";
         $paswd = "yyyyy";
         $dbstring = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)".
              "(HOST=patriot.gmu.edu)(PORT=1521))".
              "(CONNECT_DATA=(SID=COSC)))";
         $db_conn = ocilogon($username, $paswd, $dbstring);
    // username and password will be unset if they weren't passed,
    // or if they were wrong
    if( !isset($query)) {
    // just print form asking for account details
    echo "<form action=\"$uri\" method=post>\n";
    echo "<p>Enter Query: ";
    echo "<input type=text size=100 maxlength=200 name=query value=\"$query\">\n";
    echo "<br><input type=submit name=submit value=Submit>\n";
    echo "</form>\n";
    exit;
    // remove unwanted slashes from the query
    $query = stripslashes($query);
    // run the query
    $stmt = OCIParse($db_conn, $query);
    OCIExecute($stmt, OCI_DEFAULT);
    // Open the HTML table.
    print '<table border="1" cellspacing="0" cellpadding="3">';
    // Read fetched headers.
    print '<tr>';
    for ($i = 1;$i <= ocinumcols($stmt);$i++)
    print '<td class="e">'.ocicolumnname($stmt,$i).'</td>';
    print '</tr>';
    // Read fetched data.
    while (ocifetch($stmt))
    // Print open and close HTML row tags and columns data.
    print '<tr>';
    for ($i = 1;$i <= ocinumcols($stmt);$i++)
    print '<td class="v">'.ociresult($stmt,$i).'</td>';
    print '</tr>';
    // Close the HTML table.
    print '</table>';
    OCIFreeStatement($stmt);
    OCILogoff($db_conn);
    ?>

  • Saving a text file as CLOB into oracle database

    Hi techies,
    I have a text file, which I have to insert into the oracle database as a CLOB field. Please give me some code to read the file and store the contents of the file into the database.
    Thanks in advance
    Yogesh

    Hi,
    Please find attached sample code to read and write the data to the CLOB data type in the database.
    Here, the column name called "DATA" is defined as CLOB data type in the Database.
    Program Name : ClobSample.java
    JDK Version : jdk1.4
    import java.util.Properties;
    import java.util.Hashtable;
    import java.sql.*;
    import javax.sql.DataSource;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import java.util.*;
    import java.io.*;
    class ClobSample
         public static void main(String[] args) throws Exception
              Connection con = null;
              try
                   con = getConnection();
                   PreparedStatement ps = con.prepareStatement("INSERT INTO CLOBTEST(DATA) VALUES(?)");
                   String data = getMyString("c://mani.txt");
                   Reader reader = new StringReader(data);
                   ps.setCharacterStream(1, reader, data.length());
                   ps.executeUpdate();
                   System.out.println("DATA Inserted !!!!");
                   ps = con.prepareStatement("SELECT DATA FROM CLOBTEST");
                   ResultSet rs = ps.executeQuery();
                   Clob clob = null;
                   while (rs.next())
                        clob = rs.getClob("DATA");
                        System.out.println(clob.getSubString(1,(int)clob.length()));
              catch(Exception e)
                   e.printStackTrace();
              finally
                   if (con!= null)
                        con.close();
         private static Connection getConnection()
              Connection con = null;
              try
                   String url = "t3://10.3.26.16:9001";
                   Hashtable env = new Hashtable();
                   env.put(Context.INITIAL_CONTEXT_FACTORY, weblogic.jndi.WLInitialContextFactory.class.getName());
                   env.put(Context.PROVIDER_URL, url);
                   InitialContext initialContext = new InitialContext(env);
                   DataSource ob = (DataSource)initialContext.lookup("mcone.journal.txds.ds");
                   System.out.println("DataSource Object obtained--->"+ob);
                   con =ob.getConnection();
              catch(Exception exc)
                   exc.printStackTrace();
                   System.exit(0);
              return con;
         public static String getMyString(String File)
              byte a[] = null;
              try
                   InputStream fso = new FileInputStream(File);
                   a = new byte[fso.available()];
                   fso.read(a);
                   fso.close();
              catch(Exception e)
                   e.printStackTrace();
              System.out.println("DATA READ FROM THE FILE");
              return (new String( a,0,a.length));

  • Parse XML Elements/Attributes from CLOB into Oracle Table

    Hi!
    I have an XML file (loaded into a CLOB) which I need to parse and have each individual element and attribute inserted into an oracle table for manipulation.
    Eg: XML File...
    <PERSON>
    <PER_ID changed="1">1</PER_ID>
    <SURNAME changed="1">MARTIN</SURNAME>
    <ADDRESS>
    <STREET_NO changed="1">1</STREET_NO>
    <POSTCODE changed="1">LE3 8RA</POSTCODE>
    </ADDRESS>
    </PERSON>
    There will only ever be one address.
    From this I need to extract
    * PER_ID and related changed attribute
    * SURNAME and related changed attribute
    * STREET_NO and related changed attribute
    * POSTCODE and related changed attribute
    and insert a single record into the table below:
    CREATE TABLE PERSON AS
    ( PER_ID VARCHAR2(10)
    , ID_CHANGED VARCHAR2(1)
    , SURNAME VARCHAR2(30)
    , ID_CHANGED VARCHAR2(1)
    , STREET_NO VARCHAR2(5)
    , ID_CHANGED VARCHAR2(1)
    , POSTCODE VARCHAR2(10) );
    Any assistance/advice would be very much appreciated. I've tried using DBMS_XMLSave / DBMS_XMLStore which works great at pulling in elements (PER_ID, SURNAME, etc) straight into the table but doesn't look at the changed attributes, and I need both.
    Thanks a million in advance to anyone who can crack this!!
    Jay

    Try looking at this thread
    Loading datafrom a PL/SQL table into the Database table

  • Insert data into oracle based on sql server data(here sql server acting as source to oracle and destination to oracle)

    Source is Oralce. Destination is SQL Server.
    Requirement - I have to fetch sql server server data (empid's) based emp table  and send this as input data to oracle to fetch and empid's are common.
    I cannot use merge or loopkup or for each as oracle have too many records.
    For example - In MS SQL - i have empid=1,2..Only these records, I have to fetch from oracle source into sql server destination. For this, I have adopted the below approaches...The major problem I face, when i build a empid's as a string, it is taking only
    4000 chars. My string lenght is 10000. How do I breakup this string lengh and send to data flow task till all broken strings length passed to DFT.
    Approach-1
    created two variables - oraquery string, empid string
    step1 - ms sql database - created sql task - declare @empid varchar(max)
    SELECT @empid=
    Stuff((SELECT ',' + empid
            FROM  
            (SELECT  DISTINCT  convert(varchar(10),empid ) empid FROM emp
             ) x
            For XML PATH ('')),1,1,'')
    select @empid =    '(' +  @empid + ')'
    select @empid
    resultset=singlerow
    resultset=resultname=0; variablename=User::empid (empid is declared as string)
    step2 - oracle database - created data flow task
    created oledb source
    I put  this statemnt in oraquery expression - "select * from dept where dept in  "
    +  @[User::empid] + "
    expression=true
    [OLE DB Source [1]] Error: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80040E14.
    An OLE DB record is available.  Source: "Microsoft OLE DB Provider for Oracle"  Hresult: 0x80040E14  Description: "ORA-00936: missing expression".
    Approach-2
    created three variables - oraquery string, empid  int, loop object--when I put int then it is automatically setting to 0
    step1 - ms sql database - created sql task - SELECT  DISTINCT  convert(varchar(10),empid ) empid FROM emp
    resultset=fullresult
    resultset=resultname=0; variablename=User::loop
    step2 - created a for each loop container
    for loop editor - for each ado ennumerator
    enumerator configuration - loop
    variablemapping - variable=empid;index=0
    step3 - oracle database - created data flow task (outside for each loop. If I put inside it is taking long time)
    created oledb source
    I put  this statemnt in oraquery expression - "select * from dept where dept in  "
    +  @[User::empid] + "
    expression=true
    Data inserting in a destination table but  empid=0.

    Sorry didnt understand if your step3 is outside loop how
    @[User::empid] will get values for the empids from User::loop. The iteration happens inside loop so you
    need to have a logic to form the delimited list inside using a script task or something and concatenating everything and storing to variable @[User::empid]
    . Then only it will have full value used to be used in step3 query
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • DB Adaptor and inserting dates into Oracle DB

    Hi,
    I'm using the Oracle DB Adaptor to poll a table in one instance (using logical delete) and to invoke a DB adaptor to insert/merge a row into a separate instance.
    NOTE :both tables have different definitions.
    I am using a BPEL transform to tfrm the data received from the poll/receive step.
    I need to transform some date variables and the target date column CreatedTs is expecting to receive the date in the Oracle DD-MON-YYYY format (can't change the NLS_DATE_FORMAT value for the target).
    I'm trying to use the provided xsl:formatDateTime function with various formats but can't get anything useful to work.
    Any ideas ?

    Hi there,
    Please see the Bpel developer's guide at otn.oracle.com/bpel. There are two troubleshooting entries of interest:
    dateTime Conversion Exceptions
    and
    Issues with Oracle DATE
    Just search on these strings.
    The xsl:formatDateTime function is for converting xs:dateTimes to strings. If you already have a value in proper ISO dateTime format do not try to convert it. The database adapter likes that format only.
    If you are starting with a string like DD-MON-YYYY and have to convert it into a legal dateTime, then that is hard as functions like xsl:formatDateTime go the opposite way only, i.e. dateTime to string, not string to dateTime.
    A few days we had a customer who needed to convert MM/DD/YYYY to a dateTime. I am copying the solution here.
    Used the expression builder in the assign to build:
    orcl:format-string('{0}-{1}-{2}T00:00:00', substring(bpws:getVariableData('Receive_1_receive_InputVariable','ReceiverDeptCollection','/ns2:ReceiverDeptCollection/ReceiverDept/receiverEmpCollection/ReceiverEmp/someDate'), 7, 4), substring(bpws:getVariableData('Receive_1_receive_InputVariable','ReceiverDeptCollection','/ns2:ReceiverDeptCollection/ReceiverDept/receiverEmpCollection/ReceiverEmp/someDate'), 4, 2), substring(bpws:getVariableData('Receive_1_receive_InputVariable','ReceiverDeptCollection','/ns2:ReceiverDeptCollection/ReceiverDept/receiverEmpCollection/ReceiverEmp/someDate'), 1, 2))
    That worked in converting i.e. 01/05/2005 to 2005-01-05T00:00:00.
    To convert DD-MON-YYYY that is tricky because you need to first convert DEC to 12, SEP to 09, and so on. I couldn't figure out how to do that but another on this forum may be able to help you out. If you are really stuck and you know the database accepts i.e DD-MON-YYYY, you could tell the adapter that the date field is a string, then it will simply pass the value as is which should work.
    To do that please see chapter 20 of the bpel dev guide, and search for
    Configuring Offline Database Tables
    Use that to change the type to basic varchar2 in the BPEL designer so the dbadapter will think the column is a string and not convert it.
    Thanks
    Steve

Maybe you are looking for

  • Concurrency Visualizer Extension (VS2013): "An unknown error occurred while trying to start the collection process."

    Not sure if this is the right place to ask about this but since my question concerns an extension I'll give it a shot. I'm trying to use the Visual Studio 2013 Concurrency Visualizer extension to debug a simple test console application. I've set exec

  • Exporting for Flash

    I'm trying to export a motion graphic for Flash, but when I export as Lossless + Alpha Channel, I still get a black background behind my graphic that prevents me from compositing it in Flash. However, the same .mov that I exported composites without

  • Creating Content Repositories

    Hi All, We have installed Apache web server, Content Server and MaxDB on HP Unix system. further while creating content repositories in OAC0 the document area "Document Management System" is not getting selected. Looking for help on this issue. Thank

  • Windows 7 SP1 Installation Issues

    I am deploying SP1 for Windows 7 via Patch Management and I am running into some issues with the installation. I have the prerequisite installing prior the the service pack and that gets installed properly. The machines are rebooting after a time out

  • MPEG-4 And Windows

    Hello, I've got MPEG-4 videos on my website and I'm getting a lot of feedback from my windows friends saying that they aren't able to see the videos... I instruct them to download the latest Quicktime player but they still aren't able to view the vid