Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to convert a String to java.sql.Clob?

 
qionghua yang
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
I would like to convert a String variable to the java.sql.Clob datatype:
My code looks like this:
String streamHTML = (out.toString());
Clob outHTML = (Clob)streamHTML;
And of course, this code doesn't work. Hope you can help me.
Thanks a lot.
qionghua
 
Fred Abbot
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having the same problem i wish i knew how to do that
what enviorment are you using?
 
qionghua yang
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Window NT with Informix database. How about you?
qionghua
 
Fred Abbot
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
windows NT visual Age for java and an oracle database
 
Daniel Dunleavy
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred,
How are trying to insert/update oracle?
Can I see some code?
Dan
 
Daniel Dunleavy
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have either of you tried
getCharacterStream()
getAsciiStream()
???
Dan
 
Fred Abbot
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan
my problem is i am using visual age for java and therefore do not hvae a handle on the result set
I wrote some code outside of VA and it works fine
 
golfing numty
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
create clob from string for Oracle

oracle.sql.CLOB tempclob = oracle.sql.CLOB.createTemporary(
// the connection used to
// create the clob
// has to be the same as is
// used for the update
updatestmt.getConnection(), false,
oracle.sql.CLOB.DURATION_SESSION);
String clobstring = "yourdata";
try {
tempclob.setString(1, clobstring);
} catch (SQLException ex2) {


}


for non Oracle

if you have original clob data from a select
java.sql.Clob c = (java.sql.Clob) orig;
c.setString(1, "yourdata");
updatestmt.setClob(updateindex, c);

if original clob data is null - don't use clob - just use
updatestmt.setObject(updateindex, "yourdata");









 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic