Home > Ask the Oracle Database / Applications Experts > Oracle Application Server Questions & Answers > Retrieve a CLOB from the Oracle DBMS in Java
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Retrieve a CLOB from the Oracle DBMS in Java

John Garmany EXPERT RESPONSE FROM: John Garmany

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 25 April 2005
I am trying to retrieve a CLOB from the Oracle DBMS in Java so that I can use the output stream to write to it. However, I'm having a problem after I insert the row and try to retrieve the blank CLOB. I'm getting the following, "SQLException: ORA-01002: Fetch out of sequence."

Here's the code:

 
 
myPreparedStatement =
myConnection.prepareStatement ("INSERT INTO AMC_NEWB_XML VALUES (?, ?,
?, ?)");
 
                   myPreparedStatement.setString(1, mySessionId);
 
     
 
                   myPreparedStatement.setInt(2, 1);
 
                             
 
                   Calendar myCal = Calendar.getInstance();
 
                   java.util.Date myUtilDate = myCal.getTime();
 
                   java.sql.Date mySqlDate = new
java.sql.Date(myUtilDate.getTime());
 
                   myPreparedStatement.setDate(3, mySqlDate);
 
                   OracleConnection myOracleConnection =
(OracleConnection)myConnection;
 
                   myPreparedStatement.setClob(4,
oracle.sql.CLOB.empty_lob());
 
                   
 
                   int myRowCount = myPreparedStatement.executeUpdate();
 
                   myConnection.commit();
 
                   System.out.println("Successful update of
"+myRowCount+" row");
 
                   
 
                   //myReader.close();
 
                   myPreparedStatement.close();
 
                   
 
                   //Now select the clob from the row just created.
 
                   String mySql = "select XML_DATA from AMC_NEWB_XML
where SESSION_ID = ? FOR UPDATE";
 
                   CallableStatement myCallableStatement =
myConnection.prepareCall(mySql);
 
                   myCallableStatement.setString(1, mySessionId);
 
                   boolean myRes = myCallableStatement.execute();
 
                   System.out.println("Retrieved the CLOB from the DB");
 
 

>
You are using a callableStatment? CallableStatements access PL/SQL. You are just executing a SELECT. Use the PreparedStatment so that you have bind variables.

Use preparedStatment as you did when you registered the empty CLOB.

 ResultSet rs = myPreparedStatement.execute();
rs.next();
CLOB myClob = ((OracleResultSet) rs).getCLOB("XML_DATA");

// go to work on you CLOB 


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Oracle Application Server
Database objects becoming invalid
How to solve ORA-04076 error?
Receiving ORA-12541 error trying to connect through Forms/Reports
Problems connecting to database after installing Forms
Button trigger raising exception
Cause of access violation while connecting from Forms
Migrating a database to 10g and a new server
Best OS for installing database and application server on same server
Accessing an application through the Internet
Testing the accessibility of an application from outside U.A.E.

Oracle Application Server
Oracle to acquire application service management firm
Don't wait for clarity on Oracle's VM strategy, experts say
Oracle's 10 steps to get to Fusion rely on Oracle investments
Oracle Fusion Middleware: Top five headlines
Oracle-BEA deal gets the green light
Oracle adds Data Integration Suite to middleware family
Oracle-BEA deal means tough choices for middleware buyers
Oracle to buy BEA Systems
Oracle bids for BEA Systems
Oracle challenges IBM, Microsoft with application server platform
Oracle Application Server Research

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



Oracle White Papers: Fusion Middleware
HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2003 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts