writing thumbnail to blob column

hi i am taking bufferedinputstream as parameter and create thumbnail frm it and stored in blob column but when i retrive that blob column i get blank (black) image as thumbnail plz help me out i have given code here.

public int addThumbnailDtl(BufferedInputStream localbuf,InputStream inputlocal , String cvdplNo,String fileName,String folderName,String empCode,String prjName,String ext1)

throws Exception{

System.out.println("addThumbnailDtl");

ConnectionPool ovPool= null;

ConnectionovCon= null;

StatementovStmt= null;

ResultSetovResultSet= null;

ResultSetovResultSet1= null;

StringsqlStr= null;

StringsalQuery= null;

StringsqlStrUpdate= null;

introwCount=0;

intchunkSize;

byte[] binaryBuffer;

longposition=1;

long position1= 1;

intbytesRead= 0;

int bytesRead1 = 0;

intbytesWritten= 0;

inttotbytesRead= 0;

inttotbytesWritten = 0;

StringtableName= null;

Stringt_fileValue= null;

Stringt_fileName= null;

StringvId=null;

//String size=String.valueOf(fileSize);

oracle.sql.BLOB image = null;

BufferedImage thumb = null;

BufferedOutputStream outputFileOutputStream = null; // newly added 1

File ImgFile = null;// newly added 3

// BufferedImage buffimg = null;// newly added 4

Stringthumbimg= null;// newly added.

BufferedInputStream inputLocalBuf1=null;

binaryBuffer =new byte[8192];

t_fileValue = "V_FILE_CONTENTS";

try{

ovPool = new ConnectionPool();

ovCon = ovPool.createConnection();

ovCon.setAutoCommit(false);

ovStmt = ovCon.createStatement();

System.out.println("1");

salQuery="SELECT V_ID FROM FILEMANAGER_MST "+

"WHERE V_PRJ_NAME='"+prjName+"' AND V_CVDPLNO='"+cvdplNo+"'AND V_FILE_NAME='"+fileName+"'";

System.out.println("2 Query--"+salQuery);

ovResultSet= ovStmt.executeQuery(salQuery);

ovResultSet.next();

vId=ovResultSet.getString(1);

System.out.println("3 Vid "+vId);

sqlStr = "INSERT INTO FILE_THUMBNAIL VALUES('"+vId+"','"+fileName+"','"+folderName+"','111',EMPTY_BLOB(),'"+ext1+"')";

//sqlStr = "INSERT INTO FILEMANAGER_DATA VALUES('"+vId+"','"+fileName+"','"+folderName+"','111',EMPTY_BLOB(),'"+ext1+"')";

System.out.println(sqlStr);

ovStmt.executeUpdate(sqlStr);

System.out.println("Successfully Inserted Record...."+cvdplNo);

sqlStrUpdate = " SELECT "+t_fileValue+" FROM FILE_THUMBNAIL WHERE V_ID = '"+vId+"' FOR UPDATE";

System.out.println("sqlStrUpdate=> "+sqlStrUpdate);

ovResultSet1=ovStmt.executeQuery(sqlStrUpdate);

System.out.println("Successful Get Record for Update");

if(ovResultSet1 != null){

System.out.println("In If Satement");

while(ovResultSet1.next()) {

System.out.println("In While Loop");

image = (oracle.sql.BLOB) ovResultSet1.getBlob (t_fileValue);

//oracle.sql.BLOB image = ((OracleResultSet)ovResultSet).getBLOB(t_fileValue);

System.out.println("Transfer into BLOB data");

chunkSize = image.getChunkSize();

System.out.println("1");

binaryBuffer = new byte[chunkSize];

System.out.println("2");

position = 1;

System.out.println("3");

if(inputlocal==null)

{

System.out.println("blank inputlocal");

}

BufferedInputStream bInp=new BufferedInputStream(localbuf);

BufferedImage im = ImageIO.read(localbuf);

System.out.println("11");

int tw = 100;//im.getWidth()/5;

System.out.println("12");

int th = 100;//im.getHeight()/5;

System.out.println("5 "+tw+" Height"+th);

thumb = new BufferedImage(tw,th,BufferedImage.TYPE_INT_RGB);

Graphics2D gScaledImg = thumb.createGraphics();

gScaledImg.setRenderingHint(RenderingHints.KEY_INTERPOLATION,

RenderingHints.VALUE_INTERPOLATION_BILINEAR);

BufferedImage img = ImageIO.read(localbuf); // taking inputlocalbuf

gScaledImg.drawImage(img, 0, 0, 100, 100, null);

ByteArrayOutputStream out = new ByteArrayOutputStream();

ImageIO.write(thumb,"jpeg",out);

byte[] buf = out.toByteArray();

ByteArrayInputStream inStream = new ByteArrayInputStream(buf);

while ((bytesRead = inStream.read(binaryBuffer)) != -1)

{

System.out.println("OOOOOOOOOOOOOOOOOOOOOOOOOO");

bytesWritten = image.putBytes(position, binaryBuffer, bytesRead);

position+= bytesRead;

totbytesRead+= bytesRead;

totbytesWritten += bytesWritten;

}

System.out.println("7 "+position1);

/****/}

}

}catch(SQLException sqlEx){

//System.out.println("SQLException sqlstr=>"+sqlStr);

int errCode = sqlEx.getErrorCode();

String sqlMessage = sqlEx.getMessage();

String sqlState = sqlEx.getSQLState();

System.err.println("Message: " + sqlMessage);

System.err.println("SQL state: " + sqlState);

System.err.println("Error code: " + errCode);

}catch(Exception e){

System.out.println("Exception sqlstr "+e.getMessage());

}finally{

try{

ovCon.setAutoCommit(true);

ovCon.commit();

if(ovResultSet != null)

ovResultSet.close();

ovResultSet = null;

if(ovResultSet1 != null)

ovResultSet1.close();

ovResultSet1 = null;

if(ovStmt != null)

ovStmt.close();

ovStmt = null;

ovPool.close(ovCon);

ovCon= null;

ovPool= null;

}

catch(Exception err){

System.out.println("Already Closing the connection / statement / resultset");

}

}

return 0;

}

[5734 byte] By [ashok02a] at [2007-11-26 23:59:19]
# 1
First, what is a blob column, second, use the code tags
Vagabona at 2007-7-11 15:48:05 > top of Java-index,Java Essentials,New To Java...