Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Clob Blob Cnverting

  Asked By: Aysel    Date: Oct 05    Category: Java    Views: 1123
  

I have some proplem in converting String field to
java.sql.Clob and byte[] to java.sql.Blob.

I wrote it for java.sql.Clob to String and
java.sql.Blob to byte[] like the following anybody can
help me!

------------------------------------------------------

public byte[] blobToByteArray(Blob blob)
throws SQLException
{
try {
InputStream is = blob.getBinaryStream();
ByteArrayOutputStream bos = new
ByteArrayOutputStream();

if (is == null) {
return null;
}
else {
byte buffer[] = new byte[ 64 ];
int c = is.read( buffer );
while (c > 0) {
bos.write( buffer, 0, c );
c = is.read( buffer );
}
return bos.toByteArray();
}
}
catch (IOException e) {
throw new SQLException( "Failed to read
BLOB column due to IOException: " + e.getMessage() );
}
}

public Blob byteArrayToBlob(byte[] value)
throws SQLException
{
//TODO
}

public String clobToString(Clob clob)
throws SQLException
{
try {
StringBuffer sb = new StringBuffer();
InputStream is = clob.getAsciiStream();

if (is == null) {
return null;
}
else {
byte buffer[] = new byte[ 64 ];
int c = is.read( buffer );
while (c>0) {
sb.append( new String(buffer, 0,
c) );
c = is.read( buffer );
}
return sb.toString();
}
}
catch (IOException e) {
throw new SQLException( "Failed to read
CLOB column due to IOException: " + e.getMessage() );
}
}

public Clob stringToClob(String string)
throws SQLException
{
//TODO
}

}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Clob Blob Cnverting Or get search suggestion and latest updates.




Tagged: