Link to home
Create AccountLog in
Avatar of huzefaq
huzefaq

asked on

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

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
Avatar of ForceRs
ForceRs

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of huzefaq
huzefaq

ASKER

keyurkarnik:

Thanks for your time. Can you please explain your code. I didn't undertsand how I will get the value between description tags. Becasue in the String there will be many tags


Thanks again
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.