Solved

retrieving clob value from result set

Posted on 2004-08-05
5
851 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
ID: 11724966
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
ID: 11726854
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
ID: 11763843
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Data breaches are on the rise, and companies are preparing by boosting their cybersecurity budgets. According to the Cybersecurity Market Report (http://www.cybersecurityventures.com/cybersecurity-market-report), worldwide spending on cybersecurity …
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 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