Solved

retrieving clob value from result set

Posted on 2004-08-05
5
845 Views
Last Modified: 2008-02-26
hi there ;
i have some troubles in retrieving clob value from the result set, i want to exctract the DDL for a table useing Oracle 9i
API function ( dbms_metadata.get_ddl ) which returns a Clob object.
The problem is the programme gets very slow and there is no results, i have the following code :

String qry = " SELECT dbms_metadata.get_ddl('TABLE', '"+id+"','"+schema+"') FROM dual ";

  Statement stmt = con.createStatement();
  ResultSet rs = stmt.executeQuery(qry);
 
 Clob clob = null;
 if (rs.next()) {
     clob = rs.getClob(1);
 }

 how can i print out the contents of clob ? should i use inputstream to do this ?

thanx in advance
which
0
Comment
Question by:which_cyber
  • 2
5 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 50 total points
Comment Utility
From http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/advanced/LOBSample/Readme.html

-----------

  // Open a stream to read Clob data
  Reader clobStream = clob.getCharacterStream();

  // Holds the Clob data when the Clob stream is being read
  StringBuffer suggestions = new StringBuffer();

  // Read from the Clob stream and write to the stringbuffer
  int nchars = 0; // Number of characters read

  //Buffer holding characters being transferred
  char[] buffer = new char[10];
  while((nchars = clobStream.read(buffer)) != -1) // Read from Clob
    suggestions.append(buffer, 0, nchars); // Write to StringBuffer
  clobStream.close(); // Close the Clob input stream
0
 
LVL 9

Assisted Solution

by:nimaig
nimaig earned 50 total points
Comment Utility
Tyr this :

 /*
    * returns the clob object as a string
    */
    public String getClob(ResultSet rs, int index) throws SQLException{
          if(rs!=null&&rs.getClob(index)!=null)
          {
                return rs.getClob(index).getSubString(1,(new Long(rs.getClob(index).length())).intValue());
          }
          else
          {
                return null;
          }
    }
0
 
LVL 35

Expert Comment

by:TimYates
Comment Utility
Got a comment in my Feedback...  which_cyber, the best place to put things like this are in here, as people get email notifications!! ;-)

-------------

thank you very much TimYates,
but i think that i have another problem
     the programe hangs the following command :  
        clob = rs.getClob(1);

-------------

Can you post the code you have?

Tim
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
logging jar 1 104
getting Http 404 error in jsp forms 8 72
Clear browser cache on site login, is it possible? 3 23
countXY challenge 28 115
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now