This week's giveaway is in the Spring forum.
We're giving away four copies of Microservices Testing (Live Project) and have Chris Love & Andres Sacco on-line!
See this thread for details.
Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Java : Clob : Help!

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a requirement where in I have to write XML contents to Clob. This is the piece of code I have written,

File xmlFile = new File("D:\\Test\\sampleXML.xml");
BufferedReader br = new BufferedReader(new FileReader(xmlFile));
while ((xmlLine = br.readLine()) != null) {
xmlString.append(xmlLine);
}
char[] xmlBuf = xmlString.toString().toCharArray();
Clob xmlClob1 = new SerialClob(xmlBuf);
System.out.println("Clob(xmlClob1) Size = "+xmlClob1.length());
PreparedStatement pStmt = conn.prepareCall("{call insertworkfile(?)}");
pStmt.setClob(1,(Clob)xmlClob1);

But I get an error at the "setClob()" method
The error is -
java.lang.ClassCastException: javax.sql.rowset.serial.SerialClob

Can you anyone help me out of this?

I did go through lot of forums where folks spoke about using select statement to get an empty clob first,then update the clob retrieved and send it as an input. But I am not allowed to do anything like this? Can you please let me know what I need to do to solve this?
Any help is highly appreciated.
 
Ranch Hand
Posts: 1249
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take the help of following code snippet:::




Otherwise you can take the help of the below given link::
How to deal with Binary Data...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic