troubleshooting Question

How to get a substring of text while converting to String from Clob datatype

Avatar of huzefaq
huzefaq asked on
JavaJava EE
5 Comments4 Solutions915 ViewsLast Modified:
Hi guys

I have a DataBean where i am checking for Clob datatypes. If I find one I change it to a string.
Now what i need is that if I can save only the text which is between the following tags

<Description locale="en_US" type="admin">Get 40% of the highest priced item in the shop cart</Description>

So if I can only get "Get 40% of the highest priced item in the shop cart" as a String

Here is my code to convert Clob to String. I would really appreciate any help regarding this
-------------------------------------------------

for (int i = 0 ; i < resVec.size(); i++)
            {
                  Vector rowVector = (Vector) resVec.get(i);
                  for(int j=0 ; j < rowVector.size(); j++){
                        if(rowVector.get(j) instanceof Clob){
                              Clob c = (Clob)rowVector.get(j);
                              //String strClob = c.getSubString((long) 0, (int) c.length()-1);
                              //rowVector.set(j, strClob);
                              StringBuffer sb = new StringBuffer((int)c.length());
                              Reader in = c.getCharacterStream();
                              int buf = -1;
                              while((buf = in.read()) > -1) {
                                    sb.append((char)buf);
                              }
                              in.close();
                              String s = sb.toString();
                              s = s.replaceAll(",", " ");
                              rowVector.set(j, s);
                        }
                  }
---------------------------------------------------------------------------------------
ASKER CERTIFIED SOLUTION
ForceRs

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 4 Answers and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 4 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros