• 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
Marshal
Posts: 35279
384
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic