cancel
Showing results for 
Search instead for 
Did you mean: 

Store and retrieve image in database using WD Java

srinivas_sistu
Active Contributor
0 Kudos

Hi All,

I have to store and retrieve an image in oracle database. I have gone through the below blog and forum...

I am able to store image in byte format(oracle data type BLOB) and when i try to retrieve it i am not getting the image....Sorry for my poor technical knowledge.

can some body help me, please......

Regards,

G.

Accepted Solutions (0)

Answers (3)

Answers (3)

srinivas_sistu
Active Contributor
0 Kudos

Solved, problem with the JAR file.

Regards,

Srinivas

nikhil_bose
Active Contributor
0 Kudos

plz send the code.

you can try increasing the byte[] size.

refer [java code accessing BLOB|http://www.java2s.com/Code/Java/Database-SQL-JDBC/BlobandJDBCImage.htm]

nikhil

srinivas_sistu
Active Contributor
0 Kudos

Hi,

my code is working... I am able to upload and retrieve the image. But now I am getting the below exception...

Exception from image insert>> java.sql.SQLException: Data size bigger than max size for this type: 6770

Below is the code I am uing...

ConnectDataBase condb=new ConnectDataBase();

IWDMessageManager mgnr=wdComponentAPI.getMessageManager();

IPrivateDBImageView.IVn_FileElement fileelement =

wdContext.nodeVn_File().getVn_FileElementAt(0);

IWDResource resource=wdContext.currentContextElement().getResource();

InputStream in=resource.read(false);

ByteArrayOutputStream bOut=new ByteArrayOutputStream();

int lenght=0;

byte part[]=new byte [ 50000 ];

while((lenght=in.read(part))!=-1)

{

bOut.write(part,0,lenght);

}

Statement stmnt=null;

Connection con=null;

String strQuery=null;

String strProp_Details=null;

try {

con=condb.getConnection (mgnr);

stmnt=con.createStatement();

PreparedStatement pst=con.prepareStatement("insert into VMS_Image values(?,?,?)");

pst.setInt(1,4);

pst.setString(2,"srinu1234");

pst.setBytes(3,bOut.toByteArray());

pst.execute();

bOut.close();

in.close();

mgnr.reportSuccess("Inserted");

}

catch (SQLException e) {

mgnr.reportException("SQLException from image insert>>"+e,false);

}

catch(Exception e)

{

mgnr.reportException("Exception from image insert>>"+e,false);

}

finally

{

try

{

if(stmnt!=null)

{

stmnt.close();

stmnt=null;

}

if(con!=null)

{

con.close();

con=null;

}

}

catch(Exception e)

{

mgnr.reportException("Exception in Closing from image insert>>"+e,false);

}

}

first I used byte of 101024, then 501024 and finally tried with byte of 50000. I am getting the above exception if the image size is more than 4kb....

Regards,

Srinivas.

Edited by: srinivas sistu on Aug 1, 2008 2:26 PM

Edited by: srinivas sistu on Aug 1, 2008 2:34 PM

Former Member
0 Kudos

whats the problem your facing? The code is pretty straight forward. Post the code your using to retrieve the image here.

Thanks,

GLM

Edited by: GLM on Aug 1, 2008 9:48 AM