Solved

retrieving clob value from result set

Posted on 2004-08-05
5
857 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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
java.util.concurrent.locks in java 3 204
report generation frameworks 1 71
Coldfusion 10 - JSP File Not Found - 404 Error 5 109
thymeleaf natural templating vs JSP 2 165
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
We have put together a white paper that aims to explain how MSPs can both improve their offering and ease the pain of after-hours service by: -Suggesting changes to workflow -Indicating how to rework policy to suit your team -Providing ConnectW…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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