[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

retrieving clob value from result set

Posted on 2004-08-05
5
Medium Priority
?
866 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
3 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 200 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 200 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
Last month Marc Laliberte, WatchGuard’s Senior Threat Analyst, contributed reviewed the three major email authentication anti-phishing technology standards: SPF, DKIM, and DMARC. Learn more in part 2 of the series originally posted in Cyber Defense …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

834 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