Handling of CLOB type in Weblogic, JDBC

Hi All,

The below simple example will demonstrate the handling of CLOB in you JDBC call.

import java.sql.Clob;

public String readMyCLOB(int recordId){

…. code for connection,statement creation

String clobData=null;
try{
cstmt.setInt(1,recordId);
cstmt.registerOutParameter(1, Types.CLOB);
cstmt.executeQuery();

Clob clob = cstmt.getClob(2);
if (clob != null) {
BufferedReader br = new BufferedReader(clob
.getCharacterStream());
while ((bufferedLine = br.readLine()) != null) {
buffOutput.append(bufferedLine + ‘\n’);
}
}
clobData = buffOutput.toString();
}catch(Exception ex){
logger.error(ex);
}
return clobData;
}


***Note: Always import the CLOB,Array etc types from core JDBC pacakge(java.sql.*) to avoid any ClassCastExceptions in the laying Application servers.***

Thanks
R Vashi

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s