Jdbc Clob

When Iam trying to save data into clob type of oracle using Pooled Connection it is giving the following exception
java.lang.ClassCastException: weblogic.jdbc.rmi.SerialResultSet at....
But it is saving fine with Normal connection. Iam using Weblogic 6.1(sp2) and Oracle 9.9.1.1.1 with thin drivers.
The code is like this
select clob_col from tablename for update;
oracle.sql.CLOB objClob=((OracleResultSet)objResultSet).getCLOB(strColumnName);
                              Writer objClobWrite=objClob.getCharacterOutputStream();
Please help me on this issue.
Regards,
Phani

Hi Phani,
Phaneendra <[email protected]> wrote:
When Iam trying to save data into clob type of oracle using Pooled Connection
it is giving the following exception
java.lang.ClassCastException: weblogic.jdbc.rmi.SerialResultSet at....
But it is saving fine with Normal connection. Iam using Weblogic 6.1(sp2)
and Oracle 9.9.1.1.1 with thin drivers.
The code is like this
select clob_col from tablename for update;
oracle.sql.CLOB objClob=((OracleResultSet)objResultSet).getCLOB(strColumnName);
                              Writer objClobWrite=objClob.getCharacterOutputStream();
Please help me on this issue.
Regards,
PhaniWhen u r using clob or blob from weblogic you have use classes from package weblogic.jdbc.rmi
for uploading a clob do it like
ps = conn.prepareStatement("select data from urtable where ID=? for update");
ps.setString(1, ID);
ResultSet rsclob = ps.executeQuery();
if(rsclob.next()) {
weblogic.jdbc.rmi.SerialClob dclob = (weblogic.jdbc.rmi.SerialClob)rsclob.getClob(1);
try {
Writer datawrt = (Writer)dclob.getCharacterOutputStream();
datawrt.write(msg);
datawrt.flush();
datawrt.close();
catch(IOException iex) {
throw new Exception("Error while writing clob object");
rsclob.close();
u can do the similiar thing for Blob as well.
Regards
Balendran

Similar Messages

  • JDBC CLOB error

    Hi,
    I face the following error, i use the oracle jdbc driver as db driver and i use the same ojdbc14.jar file as the project library, but when i try to cast the clob object return from resutlset it throw me class cast exception, i did print out the class name it shown oracle.sql.CLOB, but when i cast the object to oracle.sql.CLOB it still show me the error.
    Do you have any idea what is wrong?
    ====================// java code
    import java.sql.Clob;
    import oracle.sql.CLOB;
    Clob clob = null;
    if ( resultSet.next() )
    clob = resultSet.getClob( 1 );
    logger.debug( "resultSet.getClass() is " + resultSet.getClass() );
    logger.debug( "clob.getClass() is " + clob.getClass() );
    logger.debug( "clob is " + clob );
    logger.debug( "(clob instanceof oracle.sql.CLOB) is " + (clob instanceof oracle.sql.CLOB));
    CLOB oraClob = (CLOB)clob; // this is where the class cast exception occur
    ====================// log file
    [10/01/2005 15:51:26] b.crrs.common.CRRSParamServlet -- DEBUG -- selectUpdateStatement is [email protected]d5b222
    [10/01/2005 15:51:26] b.crrs.common.CRRSParamServlet -- DEBUG -- resultSet.getClass() is class oracle.jdbc.driver.OracleResultSetImpl
    [10/01/2005 15:51:26] b.crrs.common.CRRSParamServlet -- DEBUG -- clob.getClass() is class oracle.sql.CLOB
    [10/01/2005 15:51:26] b.crrs.common.CRRSParamServlet -- DEBUG -- clob is oracle.sql.CLOB@1a21321
    [10/01/2005 15:51:26] b.crrs.common.CRRSParamServlet -- DEBUG -- (clob instanceof oracle.sql.CLOB) is false
    [10/01/2005 15:51:26] b.crrs.common.CRRSParamServlet -- DEBUG -- error
    java.lang.ClassCastException

    See JDBC error for CLOB

  • JDBC CLOB WRITER

    I do not know how to setup a Clob Writer - what is wrong with the following approach? (I'm getting a null pointeer exception?)
    - Tor
              Clob xmlClob = null;
              try {
                   db.open();
                   Connection c = db.getDbConnection();
                   ResultSet r = db
                             .sqlSELECT("select slm_xml_doc from slm for update ");
                   r.next();
                   ResultSetMetaData md = r.getMetaData();
                   System.out.println(" Col#: " + (1) + " Attribute: "
                             + md.getColumnName(1) + " DT: "
                             + md.getColumnTypeName(1));
                   Clob xmlclob = r.getClob(1);
              } catch (Exception s) {
                   System.out.println("DB or Clob Error: " + s.getMessage());
              try {
                   Writer writer = xmlClob.setCharacterStream(0);
              } catch (Exception s) {
                   System.out.println("Writer Error: " + s.getMessage());
    Output from unit test:
    INFO -Database connection is: oracle.jdbc.driver.T4CConnection@1172e08 (com.tor.sdmds.utilities.Database)
    Col#: 1 Attribute: SLM_XML_DOC DT: CLOB
    Writer Error: null

    FIXED - typo! Tor

  • Urgent JBO-26041: Failed to post data to database during (in insert Clob)

    HI ,
    we have a code to get the clob and then write it to the database
    HttpSession session = UIServices.getHttpSession(context);
    byte] payloadByteArray = (byte[)session.getAttribute("FILE_BYTES_fileName");
    String payloadStr = null;
    try {
    //get the string
    payloadStr = new String(payloadByteArray, "UTF-8");
    // System.out.println("---payloadstr --->>>>"+payloadStr) ;
    ClobDomain cd =new ClobDomain(payloadStr);
    XhubRoutingRulesAMImpl am = (XhubRoutingRulesAMImpl)Jbo.getApplicationModule(context);
    SnwRoutingRulesVOImpl SnwRoutingRulesVO= (SnwRoutingRulesVOImpl) am.findObject("SnwRoutingRulesVO");
    Jbo.applyViewCriteriaOneRow(SnwRoutingRulesVO,"RoutingRuleId",routingRuleId);
    SnwRoutingRulesVO.executeQuery();
    SnwRoutingRulesVORowImpl row=null;
    while (SnwRoutingRulesVO.hasNext())
    row =(SnwRoutingRulesVORowImpl) SnwRoutingRulesVO.next();
    row.setPreXslt(cd);
    row.setOverridexslt("Y");
    row.setPostXslt(null);
    //commiting the data
    Jbo.commit(am);
    session.removeAttribute("FILE_BYTES_fileName");
    catch(Exception e){
    e.printStackTrace();
    session.removeAttribute("FILE_BYTES_fileName");
    THE exception are :
    oracle.jbo.DMLException: JBO-26041: Failed to post data to database during "Update": SQL Statement "null".
    at oracle.jbo.server.EntityImpl.doDMLWithLOBs(EntityImpl.java:8139)
    at oracle.jbo.server.EntityImpl.doDML(EntityImpl.java:7994)
    at oracle.apps.snw.schema.server.WhoEntityImpl.doDML(WhoEntityImpl.java:200)
    at oracle.jbo.server.EntityImpl.postChanges(EntityImpl.java:6319)
    at oracle.jbo.server.DBTransactionImpl.doPostTransactionListeners(DBTransactionImpl.java:3168)
    at oracle.jbo.server.DBTransactionImpl.postChanges(DBTransactionImpl.java:2976)
    at oracle.jbo.server.DBTransactionImpl.commitInternal(DBTransactionImpl.java:2014)
    at oracle.jbo.server.DBTransactionImpl.commit(DBTransactionImpl.java:2273)
    at oracle.apps.snw.uicommon.Jbo.commit(Jbo.java:148)
    at oracle.apps.snw.tpadmin.webui.TPRouteRulesEvent.fileUpload(TPRouteRulesEvent.java:241)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at oracle.cabo.servlet.event.MethodEventHandler.handleEvent(Unknown Source)
    at oracle.cabo.data.jbo.servlet.event.ChainingEventHandler.handleEventImpl(Unknown Source)
    at oracle.cabo.data.jbo.servlet.event.FindRootAppModuleEventHandler.handleEventImpl(Unknown Source)
    at oracle.cabo.data.jbo.servlet.event.BaseEventHandler.handleEvent(Unknown Source)
    at oracle.cabo.servlet.event.TableEventHandler.handleEvent(Unknown Source)
    at oracle.cabo.servlet.event.TableEventHandler.handleEvent(Unknown Source)
    at oracle.cabo.data.jbo.xml.parse.JboParserExtensionImpl$SynchronizingEventHandler.handleEvent(Unknown Source)
    at oracle.cabo.servlet.event.BasePageFlowEngine.handleRequest(Unknown Source)
    at oracle.cabo.servlet.AbstractPageBroker.handleRequest(Unknown Source)
    at oracle.cabo.servlet.ui.BaseUIPageBroker.handleRequest(Unknown Source)
    at oracle.cabo.servlet.PageBrokerHandler.handleRequest(Unknown Source)
    at oracle.cabo.servlet.UIXServlet.doGet(Unknown Source)
    at oracle.cabo.servlet.BajaServlet.doGet(Unknown Source)
    at oracle.cabo.servlet.UIXServlet.doPost(Unknown Source)
    at oracle.cabo.servlet.BajaServlet.doPost(Unknown Source)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at oracle.adf.library.webapp.LibraryFilter.doFilter(LibraryFilter.java:159)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at oracle.dms.wls.DMSServletFilter.doFilter(DMSServletFilter.java:326)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3592)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2202)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2108)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1432)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
    Caused by: java.lang.NullPointerException
    at oracle.jbo.domain.ClobDomain.writeCharsToLob(ClobDomain.java:1322)
    at oracle.jbo.domain.ClobDomain.saveToDatabase(ClobDomain.java:464)
    at oracle.jbo.server.EntityImpl.doDMLWithLOBs(EntityImpl.java:8114)
    ... 49 more
    This same code is running fine sometime and we didnt get any issue but sometime it is throwing the error .Its very strange

    EDIT: Nevermind you're using ClobDomain. I was thinking of standard jdbc CLOB's.
    Edited by: Jan Nawara on May 5, 2010 10:35 AM

  • Generating large amounts of XML without running out of memory

    Hi there,
    I need some advice from the experienced xdb users around here. I´m trying to map large amounts of data inside the DB (Oracle 11.2.0.1.0) and by large I mean files up to several GB. I compared the "low level" mapping via PL/SQL in combination with ExtractValue/XMLQuery with the elegant XML View Mapping and the best performance gave me the View Mapping by using the XMLTABLE XQuery PATH constructs. So now I have a View that lies on several BINARY XMLTYPE Columns (where the XML files are stored) for the mapping and another view which lies above this Mapping View and constructs the nested XML result document via XMLELEMENT(),XMLAGG() etc. Example Code for better understanding:
    CREATE OR REPLACE VIEW MAPPING AS
    SELECT  type, (...)  FROM XMLTYPE_BINARY,  XMLTABLE ('/ROOT/ITEM' passing xml
         COLUMNS
          type       VARCHAR2(50)          PATH 'for $x in .
                                                                let $one := substring($x/b012,1,1)
                                                                let $two := substring($x/b012,1,2)
                                                                return
                                                                    if ($one eq "A")
                                                                      then "A"
                                                                    else if ($one eq "B" and not($two eq "BJ"))
                                                                      then "AA"
                                                                    else if (...)
    CREATE OR REPLACE VIEW RESULT AS
    select XMLELEMENT("RESULTDOC",
                     (SELECT XMLAGG(
                             XMLELEMENT("ITEM",
                                          XMLFOREST(
                                               type "ITEMTYPE",
    ) as RESULTDOC FROM MAPPING;
    ----------------------------------------------------------------------------------------------------------------------------Now all I want to do is materialize this document by inserting it into a XMLTYPE table/column.
    insert into bla select * from RESULT;
    Sounds pretty easy but can´t get it to work, the DB seems to load a full DOM representation into the RAM every time I perform a select, insert into or use the xmlgen tool. This Representation takes more than 1 GB for a 200 MB XML file and eventually I´m running out of memory with an
    ORA-19202: Error occurred in XML PROCESSING
    ORA-04030: out of process memory
    My question is how can I get the result document into the table without memory exhaustion. I thought the db would be smart enough to generate some kind of serialization/datastream to perform this task without loading everything into the RAM.
    Best regards

    The file import is performed via jdbc, clob and binary storage is possible up to several GB, the OR storage gives me the ORA-22813 when loading files with more than 100 MB. I use a plain prepared statement:
            File f = new File( path );
           PreparedStatement pstmt = CON.prepareStatement( "insert into " + table + " values ('" + id + "', XMLTYPE(?) )" );
           pstmt.setClob( 1, new FileReader(f) , (int)f.length() );
           pstmt.executeUpdate();
           pstmt.close(); DB version is 11.2.0.1.0 as mentioned in the initial post.
    But this isn´t my main problem, the above one is, I prefer using binary xmltype anyway, much easier to index. Anyone an idea how to get the large document from the view into a xmltype table?

  • Temporary LOBs

    Would anyone be able to explain the interaction between the duration of a temporary LOB and the action of freeing it? The JDBC CLOB/BLOB classes require you to pick a duration when creating a temporary LOB (Call or Session - what is the difference?). If the freeTemporary() method is called before the expiration of the duration, does the temporary LOB remain for the rest of the specified duration?
    Geoff

    Would anyone be able to explain the interaction between the duration of a temporary LOB and the action of freeing it? The JDBC CLOB/BLOB classes require you to pick a duration when creating a temporary LOB (Call or Session - what is the difference?). If the freeTemporary() method is called before the expiration of the duration, does the temporary LOB remain for the rest of the specified duration?
    Geoff

  • CLOB Datatype with JDBC Adapter

    Hi,
    we try to fill a Clob Datatype to JDBC Database.
    We try 2 ways with the JDBC Adapter:
    action="SQL_DML" with an SQL Statment and $placeholders$
    But how can i say the key element that it is a CLOB type?
    He used this a VARCHAR and there a not more than 4k Chars allowed.
    second way is action="EXECUTE" to call a Stored Procedure, but there we got the error that CLOB type is an Unsupported feature.
    Any Idea?
    Regards,
    Robin
    Message was edited by: Robin Schroeder

    Ok i will check this...
    But i'm right when i say that the only way to fill CLOB Type is to use a Stored Procedure ?
    or is there any possibility to do this with action="SQL_DML" ?
    Regards,
    Robin

  • Clob datatype and JDBC

    JDBC does not support CLOB, as i figured out the hard way, or is
    the version of JDBC that i have that is not supporting it.
    Can someone advise me on how do i get around this problem?
    Database that i connecting to has clob types.
    Alex
    null

    Alex Korneyev (guest) wrote:
    : JDBC does not support CLOB, as i figured out the hard way, or
    is
    : the version of JDBC that i have that is not supporting it.
    : Can someone advise me on how do i get around this problem?
    : Database that i connecting to has clob types.
    : Alex
    Follow this link for a tutorial on JDBC and CLOB using the
    Oracle JDBC driver
    http://www.oracle.com/ideveloper/99article/ta010199.html
    Oracle Technology Network
    http://technet.oracle.com
    null

  • $200 reward to solve problem with JDBC and CLOB.getCharacterOutputStream

    I'm trying to update CLOB with the getCharacterOutputStream as suggested in the example code. It works with US7ASCII DB instance but not instances in UTF8.
    I've been browsing through all the Oracle doc's and found some rather confusing statements:
    In the page at http://oradoc.photo.net/ora816/java.816/a81354/oralob2.htm#1043220
    it says: [When writing to or reading from a CLOB, the JDBC drivers perform all character set conversions for you.]
    also: [The oracle.sql.CLOB class supports all the character sets that the Oracle data server supports for CLOB types.]
    So far so good.
    In the page at http://oradoc.photo.net/ora816/java.816/a81354/oraint3.htm#1012518
    it says [The oracle.sql package supports these datatypes in several ways: CLOBs point to large fixed-width character data items (that is, characters that require a fixed number of bytes per character) and are supported by the oracle.sql.CLOB class.]
    Ooh no! Is this for real? UTF8 is variable width and does this mean it is not supported?
    Any way to get around this?
    In the page at http://oradoc.photo.net/ora816/java.816/a81358/03_pub2.htm#36009
    says [6.The mappings to oracle.sql classes are optimal because they preserve data formats and require no character-set conversions (apart from the usual network conversions). Those classes are especially useful in applications that "shovel" data between SQL and Java.]
    "No character set conversion"? Very confusing!
    I've been hammering on this CLOB/JDBC/UTF8 problem for more than a week now and I really appreciate some solutions, workarounds, or whatever help I can get. I'm running java stored procedure in 8.1.6 on Linux RH6.2.
    For your trouble, I'd pay $200 for the first guy who come up with a verifiable solution.

    This is just findings based upon your comments:
    Please refer to document Oracle8i National Language Support Guide
    Release 2 (8.1.6) from Oracle Documentation Library, Release 8.1.7
    Chapter 6 Java,
    There its clearly mention that:
    "Oracle JDBC drivers provide globalization support by allowing users to retrieve data from or insert data into a database in any character set that Oracle supports. Because Java strings are UCS2 encoded (16-bit Unicode) for JDBC programs, the target character set on the client is always UCS2. Character set conversion is required to convert data from the database character set (Db Charset) to UCS2. This applies to CHAR, LONG, CLOB, and VARCHAR2 data types; RAW data is not converted. "
    Also..please refer this...
    "oracle.sql.CLOB's method getCharacterStream() returns the contents of a CLOB as a Unicode stream."
    "The techniques that Oracle's drivers use to perform character set conversion for Java applications depend on the character set the database uses. The simplest case is where the database uses a US7ASCII or WE8ISO8859P1 character set. In this case, the driver converts the data directly from the database character set to UCS2,which is used in Java applications. "
    "If you are working with databases that employ a non-US7ASCII or non-WE8ISO8859P1 character set (for example, Japanese or Korean), then the driver converts the data, first to UTF8, then to UCS2. "
    In my case the characte-set of the database is WE8ISO8859P1 and for security reason i can't change the character set but my feeling is that if you are updating the CLob from the java client you are forming a reference of a clob in the client which is UCS2 at the Java side. Now when you are populating the clob through java.io.Writer and call the procedure to pass the reference of the clob to the procedure then I believe the JDBC will convert the UCS2 datatype of Clob to UTF8 in the database.
    You can try out the code snippet:
    package ServletGDC;
    import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import oracle.sql.*;
    import java.sql.*;
    import oracle.jdbc.driver.*;
    import ClassesGDC.*;
    public class testUpload extends HttpServlet {
    private String m_strMessage="";//It stores the message to be uploaded along with the Document
    Connection conn=null;
    public void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {
    String strContent="";
    //res.setContentType("application/msword");
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();
    try {
    CallableStatement cmt=null;
    OutputStream output=null;
    ByteArrayOutputStream byteoutput=null;
    String strDocString="";
    oracle.sql.CLOB tempClob = null;
    String strPassedFileName="";     // the file name passed in the request object
    String strStdFilename="";//the file name to be given to the best practice
    String strSaveDirectory="";     //the directory in which the bp is to be saved
    String strParamName="";//name of parameters
    String strParamValue="";//value of parameters
    int intTempVariable=0; // temporaty variable
    long lngSizeOfFileUploaded=0;//stores the size of the file which had been uploaded in the file system
    File filePathOfFileUploaded=null;//stores the path of the file uploaded to the file system
    String strQuery="";
    //ST------------checks if the user has logged in or not-----------------------
    HttpSession session=req.getSession(true);
    if(req.getContentLength()>20*1024*1024)
    throw new skip("The size of the posted content is more than 10 MB . If you have a best practice whose size is more than 1 MB please mail it to Us.");
    byteoutput = new ByteArrayOutputStream();
    MultipartParser mp = new MultipartParser(req, 20*1024*1024); // 10MB is the limit of the file to be uploaded
    Part part;//Its an abstact part which helps in retrieving information about the file and the parameters
    while ((part = mp.readNextPart()) != null) {//Reads the next part
    strParamName = part.getName();
    // the following if is executed if the part is for a parameter rather than a file
    if (part.isParam()) {
    }else if (part.isFile()) {
    // it's a file part
    m_strMessage="inside file part";
    FilePart filePart = (FilePart) part;
    strPassedFileName = filePart.getFileName();
    strContent= filePart.getContentType();
    out.println("<BR><font color=red>strPassedFileName is "+strPassedFileName+"</font>");
    if(strPassedFileName != null || !(strPassedFileName.trim().equals("")) ) {
    // the part actually contained a file
    out.println("<BR><font color=red> before forming long</font>");
    //lngSizeOfFileUploaded = filePart.writeTo(filePathOfFileUploaded);      //the statement upload the bestpractice in the
    lngSizeOfFileUploaded = filePart.writeTo(byteoutput);     //specified file path filePathOfFileUploaded.
    out.println("<BR><font color=red> after file is written into the outputstream</font>");
    else {
    throw new skip("The file name is null or it is empty space. Files in such Format are not accepted");
    }//end of else if
    }//end of while loop
    if(     lngSizeOfFileUploaded==0)     {// the size of the file uploaded is zero then the file supplied was not proper and hence exception is to be thrown
    //if(filePathOfFileUploaded.exists())
    //     filePathOfFileUploaded.delete();
    throw new skip("The File could not be uploaded,Possible reasons may be that the file is sent null or the file is corrupted");
    //END---------------the file is uploaded in the proper directory--------------------
    //res.setContentType(strContent);
    out.println("<BR><font color=red>long value is : "+lngSizeOfFileUploaded+" and content is "+strContent+"</font>");
    String strbyte= byteoutput.toString();
    byteoutput.flush();
    Class.forName("oracle.jdbc.driver.OracleDriver");
    // Establish network connection to database
    conn = DriverManager.getConnection("jdbc:oracle:thin:@pc-p32670:1521:GDCDBI","gdc_user","myuser");
    //if(conn!=null)
    out.println("<BR><font color=red>Connection formed"+conn);
    //els
    //out.println("<BR><font color=red>long value is : "+strbyte+"</font>");
    try{
    tempClob = oracle.sql.CLOB.createTemporary(conn,true, oracle.sql.CLOB.DURATION_SESSION);
    out.println("<BR><font color=red>tempClob : "+tempClob);
    tempClob.open( oracle.sql.CLOB.MODE_READWRITE);
    java.io.Writer tempClobWriter = tempClob.getCharacterOutputStream();
    // writing the string formed from the multipart file to the clob
    tempClobWriter.write(strbyte);
    if(tempClob!=null){}
    out.println("<BR><font color=red>CLOB value is : "+tempClob+"</font>");
    strQuery="{call INSERT_CLOB(?,?)}";
    cmt=conn.prepareCall(strQuery);
    cmt.setString(1,strPassedFileName);
    cmt.setClob(2,tempClob);
    cmt.registerOutParameter(2,java.sql.Types.CLOB);
    cmt.execute();
    tempClobWriter.flush();
    tempClobWriter.close();
    tempClob.freeTemporary();
    //res.setContentType(strContent);
    //strDocString.toString();
    out.println("<BR><font color=red>bob is "+strbyte+"</font>");
    tempClob.close();
    }catch(Exception e){
    tempClob.close();
    out.println("<font color=blue> Error is :"+e.getMessage()+"</font>");
    //e.printStackTrace(out);
    cmt.close();
    //out.println("<BR><font color=red><h2><b>SUCCESS</h2></font>");
    //res.sendRedirect("../test/showfile.jsp?contentype="+strContent.trim()+"");
    }catch(Exception e){
    java.util.Date d = new java.util.Date();
    String s =d.toString();
    out.println("<font color=blue> Error is :"+e.getMessage()+"</font>");
    //e.printStackTrace(out);
    }finally{
    try{
    if(conn!=null)
    conn.close();
    }catch(Exception e){
    out.println("<font color=blue> Error is :"+e.getMessage()+"</font>");
    }// end of finally
    } //end of doPost
    } //end of class
    in the Procedure you will be inserting/updating the clob in a table with the reference clob in the out parameter of the procedure
    Thanks.

  • 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...

  • Creating a CLOB in jdbc

    I have a PL/SQL stored procedure which accepts a CLOB data type as one of the arguments. This procedure inserts a record into a table which has a column of datatype CLOB.
    Using jdbc, my java program creates a CallableStatement to the stored proc. Now I wish to create the CLOB based on a String value and pass it to the stored proc.
    This is a snippet of my code.
    import java.io.*;
    import java.sql.*;
    import oracle.jdbc.driver.*;
    import oracle.sql.*;
    public class TestClob2 {
    public static Connection getConnection() throws FPError {
    Connection connection = null;
    String hostname= "ahost";
    String host = "jdbc:oracle:thin:@" + hostname+ ":1521:db";
    String user = "user";
    try {
    DriverManager.registerDriver( new oracle.jdbc.driver.OracleDriver());
    connection = DriverManager.getConnection(host, user, user);
    } catch ( Exception e ){
    System.out.println("could not get connection" + e.toString());
    } catch ( Throwable t ){
    System.out.println("could not get connection" + t.toString());
    } finally {
    return connection;
    public static void main( String[] args){
    Connection con = null;
    try {
    con = getConnection();
    OracleCallableStatement stmt = (OracleCallableStatement) con.prepareCall("{call plsqlStoredProc(? )}");
    String message="Test for Clob";
    try
    oracle.sql.CLOB cl = new oracle.sql.CLOB( (OracleConnection) con);
    //byte[] msg = message.getBytes("UTF8");
    //CLOB cl = new CLOB( (OracleConnection) con, msg);
    if ( cl == null ) System.out.println("clob is null");
    long index = cl.getLength();
    System.out.println("length is " + l );
    int i = cl.putString(index+1, message);
    stmt.setCLOB(1, cl);
    stmt.executeUpdate();
    catch (SQLException excep)
    System.out.println(excep.getMessage());
    excep.printStackTrace();
    //new LogException(excep.getMessage());
    } catch (Exception e ) {
    System.out.println("caught exception " + e.toString());
    e.printStackTrace();
    } finally {
    try { if (con != null ) con.close(); } catch ( Exception e){ }
    I get the following error
    caught exception java.lang.NullPointerException:
    java.lang.NullPointerException:
    at oracle.sql.Datum.getBytes(Datum.java:147)
    at oracle.jdbc.driver.OraclePreparedStatement.setCLOB(OraclePreparedStat
    ement.java)
    at oracle.sql.CLOB.plsql_write(Compiled Code)
    at oracle.jdbc.ttc7.TTC7Protocol.lobWrite(TTC7Protocol.java)
    at oracle.sql.CLOB.putChars(CLOB.java)
    at oracle.sql.CLOB.putString(CLOB.java)
    at TestClob3.main(TestClob3.java:38)
    Can anybody tell me how I can create a CLOB in jdbc to pass it over to a PL/SQL stored proc.
    When I test the stored procedure using a PL/SQL proc ( creating a temporary clob and passing it to the stored proc ) it works fine.
    Can somebody point out the mistake in my code. Appreciate it.
    Thanks.
    null

    Hello,
    First of i must admit that i am naive to installation softwares. But i can tell u that u can create tables using java and jdbc. I have done it myself. As far as creating database in concerned i haven't tried it out yet. But my gut feeling is that u can create it. I u are interested in having a look at the sample code then here it is.
    import java.sql.*;
    public class demoddl
    public static void main(String[] args) throws SQLException
    try
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection con = DriverManager.getConnection("jdbc:oracle:thin:@10.0.0.8:1521:oraserv","scott","lion");
    Statement stmt = con.createStatement();
    boolean b = stmt.execute("create table demoddl(a number)");
    System.out.println("Boolean
    catch(Exception e)
    System.out.println("Exception="+e.toString());
    }

  • Calling PLSQL Procedure with CLOB input parameter from JDBC

    Hi..
    I've got a PLSQL procedure with a CLOB object as input parameter:
    function saveProject (xmldoc CLOB) RETURN varchar IS
    I want to call that procedure from my JDBC Application as...
    String data = "..."
    CallableStatement proc = conn.prepareCall
              ("begin ? := saveProject (?); end;");
    neither
    proc.setCharacterStream(2, new StringReader(data, data.length());
    nor
    proc.setString(2, data);
    will work.
    The Application throws java.sql.Exception: ... PLS-00306 wrong
    number or types of arguments in call 'SAVEPROJECT'
    How can I use set setClob method?
    The Problem is: with Oracles CLOB implementation I can't create
    an Instance, and from the CallableStatement a can't get a
    Locator for a CLOB-Object.
    This CLOB stuff makes me really nuts!
    please somebody help me.. thanks
    Alex

    Hi All,
    You can not make it like that.
    You can not make clob as input parameter.
    Do you want an easy way?
    This is the easy way.
    sample:
    function myFunction(S varchar2(40))
    return integer as
    begin
    insert into TableAAA values(S)
    --TableAAA only contains 1 column of clob type
    end;
    This will work the problem with this is the parameter is in
    varchar2 right? so there will be limited length for it.
    You can do this to call that function:
    nyFunction('My String that will be input into clob field');
    There's another slight difficult way, I understand that you have
    installed Oracle client/server in your system, try to look at
    jdbc folder and try to find demo.zip in that folder, you can
    find several ways of doing thing with jdbc.
    Have a nice day,
    Evan

  • Empty CLOB field value from Oracle database using JDBC Sender

    Hi All,
    I am selecting a CLOB field from Oracle database table using JDBC Sender adapter and getting error "NullPointerException"
    Seen SAP note 1283089 but its not applicable for my support pack PI 7.0 SP 12 and client dont want to upgrdate SP 17 right now.
    I tried rpad(1,0)Column_Name funciton in JDBC select query but it selcting blank value for every record even those having some value for this CLOB field so not useful
    Could anybody suggest possible way? client dont want to change anything at database side.
    Thanks,
    Dharamveer

    What is the Oracle driver version installed? You might need to install 10.x driver if not already using it.

  • ORA-03115 Error using CLOB with JDBC

    When I try to access CLOB field data with JDBC driver, I gets following error:
    ORA-03115: unsupported network datatype or representation.
    I am using JDBC 8.1.6(Thin), Oracle 8.0.5
    on Linux OS.
    what's the problem ?
    Thank you for any help.
    Taesoo.
    null

    if it is a bug, then its better to upgrade the database to 10.2.0.4. it is the stable verion in 10g.

  • Problem using CLOB in JDBC (NewLOBAPISample)

    I've just tried to run the JDBC NewLOBAPISample, and everything works fine until I try to insert or update on the CLOB column using any characters other than base ASCII. For example, if I attempt to insert the String "$100", it works just fine, but "£100" results in:
    java.sql.SQLException: No more data to read from socket
    I've experimented with this issue with a much smaller test case of my own, and I've been able to narrow down the problem, as I've outlined below. In all cases, PreparedStatement is used for executing.
    Let's say we have a table named "Test" with one CLOB column named "text".
    The original "official" API for inserting a CLOB using the latest 1.4 JDBC Oracle thin driver is:
    // first insert an "empty CLOB"
    PreparedStatement ps;
    ps = con.prepareStatement("INSERT INTO Test (text) VALUES (empty_clob())");
    ps.executeUpdate();
    // then select the empty CLOB
    con.setAutoCommit(false);
    ps = con.prepareStatement("SELECT text FROM Test FOR UPDATE");
    ResultSet rs = ps.executeQuery();
    rs.next();
    CLOB clob = ((OracleResultSet)rs).getCLOB(1);
    // now write to the CLOB
    Writer out = clob.getCharacterOutputStream();
    out.write(myLongText);
    out.close();
    // we're done
    connection.commit();
    The method that is advertised in NewLOBAPISample, and which I've also seen on the Java Developer Forum, is outlined here:
    // first, create statement to insert
    PreparedStatement ps;
    ps = con.prepareStatement("INSERT INTO Test (text) VALUES (?)");
    // create a temporary CLOB and write to it
    CLOB clob = CLOB.createTemporary(con, true, CLOB.DURATION_SESSION);
    Writer out = clob.getCharacterOutputStream();
    out.write(myLongText);
    // set the CLOB on the PreparedStatement and execute
    ps.setClob(1, clob);
    ps.executeUpdate();
    Now, in the above two cases, if "myLongText" has any characters in it besides standard alpha-numerics, the latter approach will fail, although the former (original) approach will still work. In my case, I need to save Danish characters in the CLOB data. (I can't type these characters in this message, as for some reason they are being converted to "æ å ø" during posting, instead of the letters I've typed on my keyboard.)
    Here is a stack trace when I try the createTemporary approach with a short String that contains one or more non-standard characters:
    java.io.IOException: No more data to read from socket
         at oracle.jdbc.dbaccess.DBError.SQLToIOException(DBError.java:716)
         at oracle.jdbc.driver.OracleClobWriter.flushBuffer(OracleClobWriter.java:270)
         at oracle.jdbc.driver.OracleClobWriter.close(OracleClobWriter.java:232)
    Here's the strack trace when the insert String contains only ONE character that is non-standard:
    java.sql.SQLException: No more data to read from socket
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
         at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:1160)
         at oracle.jdbc.ttc7.MAREngine.unmarshalUB1(MAREngine.java:963)
         at oracle.jdbc.ttc7.MAREngine.unmarshalSB1(MAREngine.java:893)
         at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:369)
         at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
         at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
         at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
         at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
         at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)
         at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
    Any help with this would be MUCH appreciated.
    Thanks,
    David Karlton

    hi David,
    i tried inserting non-alphanumeric chars but still it goes thru fine.
    here is what i did,
    create table testlob ( id number(5),lobcol clob);
    LobInJava.java
    import java.sql.*;
    import oracle.jdbc.*;
    import oracle.sql.*;
    class LobInJava
    public static void main(String args[]) throws Exception
    DriverManager.registerDriver(new
    oracle.jdbc.driver.OracleDriver());
    Connection conn = DriverManager.getConnection
    ("jdbc:oracle:thin:@host:1522:ora9idb", "scott", "tiger");
    StringBuffer myLongText = new StringBuffer("nm{H$ñVmZ".length() * 10 );
    for(int i=0 ;i < 1000 ;i++ )
    myLongText.append("nm{H$ñVmZ");
    System.out.println( myLongText.length());
    PreparedStatement ps;
    ps = conn.prepareStatement("INSERT INTO Testlob (id,lobcol) VALUES (2,empty_clob())");
    ps.executeUpdate();
    // then select the empty CLOB
    conn.setAutoCommit(false);
    ps = conn.prepareStatement("SELECT lobcol FROM Testlob where id=2 FOR UPDATE");
    ResultSet rs = ps.executeQuery();
    rs.next();
    CLOB clob = ((OracleResultSet)rs).getCLOB(1);
    // now write to the CLOB
    java.io.Writer out = clob.getCharacterOutputStream();
    out.write(myLongText.toString());
    out.close();
    // we're done
    conn.commit();
    ps.close();
    // first, create statement to insert
    PreparedStatement ps;
    ps = conn.prepareStatement("INSERT INTO Testlob (id,lobcol) VALUES (1,?)");
    // create a temporary CLOB and write to it
    CLOB clob = CLOB.createTemporary(conn, true, CLOB.DURATION_SESSION);
    java.io.Writer out = clob.getCharacterOutputStream();
    out.write(myLongText.toString());
    out.close();
    // set the CLOB on the PreparedStatement and execute
    ps.setClob(1, clob);
    ps.executeUpdate();
    ps.close();
    conn.close();
    i am using jdk 1.3 and Oracle9i v9.0.1
    Regards
    Elango.

Maybe you are looking for