Hi all, here is my problem
I need to insert and retrieve the image file from the database.
I am using
http://www.servlets.com/cos/index.html package for dealing with multipart request when uploading the file.
I am then inserting the file into the database.
I think it is inserting the file properly into the database.
now I need to retrieve the image blob from the database and display it in the browser.
here is my
servlet code :
import java.util.*;
import java.io.*;
import java.sql.*;
import oracle.jdbc.driver.*;
import oracle.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class blobview extends HttpServlet
{
private BLOB myblob;
private
String mname="";
public void doGet (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("image/gif");
Connection con=null;
Statement stmt =null;
ResultSet resl=null;
String flname=req.getParameter("fname");
try
{
DriverManager.registerDriver( new oracle.jdbc.OracleDriver());
con =DriverManager.getConnection("jdbc

racle

ci8:@test1","rpalwai","rp6701");
con.setAutoCommit(false);
stmt = con.createStatement();
resl = stmt.executeQuery("SELECT NAME, BFILE FROM SAMPLEBLOB WHERE NAME = '" + flname + "'");
while( resl.next() )
{
//mname=resl.getString("NAME");
myblob = ((OracleResultSet)resl).getBLOB ("BFILE");
InputStream blobStream = myblob.getBinaryStream();
int chunkSize=myblob.getChunkSize();
byte [] byteBuffer=new byte[chunkSize];
String saveFile=targetDir + flname;
FileOutputStream fileOutStream = new FileOutputStream(flname);
int bytesRead;
while((bytesRead = blobStream.read(byteBuffer))!= -1)
{
fileOutStream.write(byteBuffer);
}
fileOutStream.close();
blobStream.close();
}
}
catch (SQLException e)
{
throw new IOException("Database Error querying insert new file"+e.getMessage());
}
finally
{if(stmt!=null)
{
try
{
stmt.close();
con.close();
//con.commit();
}
catch(SQLException e)
{
}
}
}
}
}
This code does not work. it just displays an image icon not actual image.
please help
thanks,
reddy