How to save files as blob into DB2? (Using struts and jsp)

Hello all, i need to save my uploaded file into a blob column in db2. Are there any sample codes for me to reference?P.S. If possible, i would want to store the exact filename uploaded instead of creating a new file for it.Thx alotMessage was edited by: NgSG
[293 byte] By [NgSGa] at [2007-10-3 2:26:43]
# 1

Hi

this is done pretty easily with struts, the only 'catch' is that you cant use regular SQL statements (I think) for BLOB.

I guess you know how to upload file and the only problem for you is insert to database, right?

Probably there is more elegant way to do this, but this worked for me using MySQL, and this is part of code you're looking for in your ActionClass:

FormFile uploadedFile = uploadForm.getFile();

String uploadedFileName = uploadedFile.getFileName();

PreparedStatement pst = conn.prepareStatement("insert into your_database values(?, ?)");

InputStream inputStream = uploadedFile.getInputStream();

pst.setString(1, uploadedFileName);

pst.setBinaryStream(3, inputStream, uploadedFile.getFileSize());

pst.execute();

djordjewa at 2007-7-14 19:25:47 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...