Solved

retrieving clob value from result set

Posted on 2004-08-05
5
855 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tomcat users xml 7 128
web service Rest Client creation 4 91
spring AOP 6 88
struts exact match support 3 57
The business world is becoming increasingly integrated with tech. It’s not just for a select few anymore — but what about if you have a small business? It may be easier than you think to integrate technology into your small business, and it’s likely…
This article describes how to reset your Windows 10 password when you've forgotten it.
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

829 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