• Post Reply Bookmark Topic Watch Topic
  • New Topic

string to clob without database connection

 
Michael Stickler
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

is it posible to instanciate an clob to write a string or stringbuffer in. i have no database connection at this time. i will only return a clob to a other function.
or is there a alternative to save an xml file to oracle database.

thx

greetingx
michael
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36032
432
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael,
Welcome to JavaRanch!

I'm confused about what you are trying to do. If you don't have a database connection, why do you need a CLOB?
 
Wei Dai
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should use:
public class StringClob implements Clob {

private String stringData;

public String toString() {
return stringData;
}

public StringClob(String value)
stringData=value;
}

public long length() throws SQLException {
return stringData.length();
}
public String getSubString(long pos, int length) throws SQLException {
if(stringData.length()==0)return stringData;
if( pos > stringData.length() || pos < 1) {
throw new SQLException("Starting position for getSubString can not be < 1 or >"+ stringData.length());
}
if( length> stringData.length() - pos+ 1 ) {
length = (int)(stringData.length() - pos+ 1);
}
return stringData.substring((int) pos-1, length);
}
public Reader getCharacterStream() throws SQLException {
return new StringReader(stringData);
}
public InputStream getAsciiStream() throws SQLException {
return new ByteArrayInputStream(stringData.getBytes());
}
public long position(String searchstr, long start) throws SQLException {
if( start > stringData.length() || start < 1) {
throw new SQLException("Starting position for search can not be < 1 or >"+ stringData.length());
}
int pos=stringData.indexOf(searchstr, (int) start-1);
return (pos == -1) ? (-1) : (pos + 1);

}
public long position(Clob searchstr, long start) throws SQLException {
return position(searchstr.getSubString(0L, (int) searchstr.length()), start);
}
}

Good luck
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!