Why can't i retrieve image on web page that store on SQL DB?
I want to retrieve image on web page that store on sql.I read many forums about that but i can't until now.I have no errors but no image is display.When i retrieve to byte array from sql that i store the image value, the value is change.Pls give me some advice how should i do?
I use *Servlet Page*.My code is...
//////////////////////////// to retrieve from DataBase ///////////////////////////////////
public class DB {
String result="";
public static String type="";
String data="jdbc:odbc:auctionDB";
private static DB myDB;
public byte[] showPhotos(String type){
byte[] result=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection(data,"","");
Statement st=conn.createStatement();
ResultSet rec=st.executeQuery("SELECT * FROM Upload WHERE type='"+type+"'");
if(rec.next()){
result=rec.getBytes(4);
System.out.println("in DB:"+result);
}
}catch(SQLException ex){
System.out.println("sql exception in checkID: "+ex.toString());
}catch(Exception e){
System.out.println("exception in checkID: "+e.toString());
}
return result;
}
}
/////////////////////////////// to display image on servlet page ////////////////////////////////
public class displayPhoto extends HttpServlet {
private static final String CONTENT_TYPE = "text/html";
DB db=auctionsite.DB.getDataBase();
byte[] atphoto;
JLabel imglbl;
ImageIcon img;
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
byte[] photo=db.showPhotos("edevices");
System.out.println("in doGet:"+photo);
OutputStream out=response.getOutputStream();
response.setContentType("image/jpeg");
out.write(photo);
}
}

