prabhu.cyber 0 Newbie Poster

im tring to display image from database with som text but i didn't get it but it shows only the data not

showdata.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%> <%@ page import="java.sql.*" %> <%@ page import="java.io.*"%> <%@ page import="java.util.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <table border="1"> <tbody> <tr> <td>id</td> <td>name</td> <td>image</td></td> <%
  try{

     Class.forName("com.mysql.jdbc.Driver"); 
     Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","password"); 
     PreparedStatement sts=con.prepareStatement("select * from phototable");
     Statement st=con.createStatement();
     ResultSet rs=st.executeQuery("select imgid,name,bimage from phototable");
     ResultSet rss=sts.executeQuery();
     while(rss.next())
     {
  %> <tr> <td><%out.println(rss.getString(1)); %></td> <td><%out.println(rss.getString(2)); %> </td> <td> <img src="http://localhost:8080/checkmysdhop/Uploadimage.jsp?imgid=<%rss.getString(1); %>" width="90" height="90"> </td> </tr> <%} %> <%   
  } 
  catch(Exception e) 
  { 
    out.println(e.toString());
  }
  %> </tbody> </table> </body> </html>

uploadimage.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ page import="java.sql.*" %> <%@ page import="java.io.*"%> <%@ page import="java.util.*"%> <html> <head> </head> <body> <% 
String id=request.getParameter("imgid");
Blob image=null;
byte[] img=null;
Connection con=null;
Statement st=null;
ResultSet rs=null;


try{

   Class.forName("com.mysql.jdbc.Driver").newInstance(); 
    con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","password"); 
    st=con.createStatement();
    String sql="select bimage from phototable where imgid="+id;
   rs=st.executeQuery(sql);
   while(rs.next())
   {
       image=rs.getBlob(1);
       img=image.getBytes(1,(int)image.length());

    response.setContentType("image/gif");
  OutputStream o=response.getOutputStream();
  %> <img src="<%o.write(img);%>" width="10" height="20"> <img src="<%o.write(img);%>" width="10" height="20"> <% 
  o.flush();
  o.close();
  i++;
   }
  out.println("success");
   } 
   catch(Exception e) 
   { 
     out.println(e.toString());

   } 


%> <p>hiiiii</P> </body> </html>

image please help me im new in jsp

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.