aspose file tools*
The moose likes JDBC and the fly likes Clob and String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Clob and String" Watch "Clob and String" New topic
Author

Clob and String

Signor Rana
Greenhorn

Joined: Jan 24, 2004
Posts: 4
How can I convert read clob as a string ?
I am selecting data from table which is clob data type, How I
can I convert it into string.
I can insert but nor read? any clue!
Thanks
Signor Rana
Greenhorn

Joined: Jan 24, 2004
Posts: 4
I did create method!
import java.io.*;
import java.lang.*;
import java.sql.*;
public class Clob2String {
public Clob2String() {
}
public String convertClob2String(java.sql.Clob clobInData) {
String stringClob = null;
try {
long i = 1;
int clobLength = (int) clobInData.length();
stringClob = clobInData.getSubString(i, clobLength);
}
catch (Exception e) {
System.out.println(e);
}
return stringClob;
}
}
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31057
    
232

Signor,
Why can't you just do rs.getString() when getting the value from the db?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Signor Rana
Greenhorn

Joined: Jan 24, 2004
Posts: 4
rs.setString(ClobValue);
work when i am saving the data but rs.getString() is getting null ? when reading from db?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31057
    
232

Signor,
That's odd. I use getString() and it works. Are you sure the row has a value in it? Are you getting a null string? Try calling rs.wasNull() to see if the database thinks it has a null value.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Clob and String