nishant srivastava
image displaying from database with some other information
0 Answer(s)      4 years and 3 months ago
Posted in : JSP-Servlet

hi, in the following section of code when i am not displaying the image it is working properly but when i tried to display the image nothing is displayed on browser only a cross mark is shows. same code runs if i am not retriveing any data from admin table my image table has two entries img blob and and id rest have admin table entries.

<%@ page import="java.io.*"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
    <form>
        <%@page import="java.sql.*" %>

        <%
        HttpSession ses=request.getSession(false);

         int admin_id=Integer.parseInt(ses.getAttribute("admin").toString());

            Connection con=null;
            PreparedStatement smt1 = null;
            ResultSet rs1 = null;           
try{

    Class.forName("com.mysql.jdbc.Driver");
               con=DriverManager.getConnection("jdbc:mysql://localhost:3306/online","root","root");
          // smt=con.prepareStatement("select aname,aemail from admin where admin_id=?");
               // smt.setInt(1,admin_id);
                //rs=smt.executeQuery();
byte[ ] imgData = null ;

Blob image = null;

  smt1=con.prepareStatement("select img,aname,aemail from image inner join admin on image.id=admin.admin_id where admin.admin_id=?");

  smt1.setInt(1,admin_id);

                rs1=smt1.executeQuery();
               if(rs1!=null && rs1.next())
                {
image = rs1.getBlob(1);

imgData = image.getBytes(1,(int)image.length());

       %>
 <table width="628" height="573" border="0">
    <tr>
      <th width="591" scope="col"><table width="324" border="0">
        <tr>
          <th width="168" scope="col"><font color="white">Name</font></th>
          <th width="146" scope="col">
              <input type="hidden" name="hiddenField"><font color="red"><%=(rs1.getString("aname"))%>
       </font>
        </tr>
        <tr>
          <th scope="row"><font color="white">Admin ID </th>
          <th scope="row"></font>
               <input type="hidden" name="hiddenField"><font color="red"><%=admin_id%>
</font>
</th>
        </tr>
        <tr>
          <th scope="row"><font color="white">Email ID</th>
          <th scope="row"></font>
          <input type="hidden" name="hiddenField"><font color="red"><%=(rs1.getString("aemail"))%>
</font>
          </th>
        </tr>
        <table width="500" border="0">

<td colspan="5" style="background-color:#FFA500;">
<img src="">
<%response.setContentType("image/gif");

OutputStream o = response.getOutputStream();

o.write(imgData);

o.flush();

o.close();
 %>
</td>

        </table>
      </table>
        <p>
</div>
<%
    }
            }
            catch(ClassNotFoundException e)
            {
                out.println("class not found"+e.getMessage());
            }
            catch(SQLException e)
            {
                out.println("sql excep"+e.getMessage());
            }
            finally
            {
                try{
                    if(con!=null)
                        con.close();
                    }
                 catch(Exception e)
                    {
                    }
            }
%>
</form>
</body>
</html>
Advertisement
View Answers









Related Tutorials/Questions & Answers:
image displaying from database with some other information
image displaying from database with some other information  hi, in the following section of code when i am not displaying the image it is working...=con.prepareStatement("select img,aname,aemail from image inner join admin
Displaying file from database
Displaying file from database  I have list of files in my database. I... that corresponding file from database. I have list of file id related to search. I want to retrieve and display all the file using list of file ID. Is there is any other way
Advertisements
get information from database
get information from database  get information from database   Please visit the following links: http://www.roseindia.net/sql/mysql-table/mysql-php-select.shtml http://www.roseindia.net/sql/mysql-example/select
Displaying Database information on the browser.
PHP DATABASE Information Part-5(b): Displaying Data (with the help of PHPMyAdmin) Up to now, we learned how to create database and insert information in the database. In this tutorial, I will show you how to insert the information
Fetching image from database
Fetching image from database  I have uploaded image path and image name in database so, now how can i display that image using JSP or HTML page... in database is:E:\1003\54175\20110407121554 image name i have stored
displaying data retrieved from a database in a jsp page
displaying data retrieved from a database in a jsp page  the page... none of the required information is displayed except the tagline protected void... sql = "select billid, customerid, billdate, status from customerbills where
jsp programe for displaying data from database
jsp programe for displaying data from database  i am using JSP.i want to insert data into database and also want to display the things i have entered... these data.plz some one help me..i m going to submit my project next week..  
jsp programe for displaying data from database
jsp programe for displaying data from database  i am using JSP.i want to insert data into database and also want to display the things i have entered... these data.plz some one help me..i m going to submit my project next week..  
jsp programe for displaying data from database
jsp programe for displaying data from database  i am using JSP.i want to insert data into database and also want to display the things i have entered... these data.plz some one help me..i m going to submit my project next week..  
Image is not displaying
Image is not displaying  Hii i am using spring javamail with html template to send mail,i am facing that image displaying prob when mail have to cm in gmail,in template just i am giving my current location of image which
jfreechart displaying chart from access database
jfreechart displaying chart from access database  I have these 2 codes. array.java----in which i retrieve the values from the database . import... javax.servlet.http.HttpServletResponse; /** * * @author AARUSHI */ class database { int roll; String
displaying image
displaying image  how to upload image and retrieve it form database mysql in php?   Here is an example of uploading image using php. 1)form.html: <form method="post" enctype="multipart/form-data" action="upload.php
How to retrive an inmage from database and displaying it in imgae box - Swing AWT
How to retrive an inmage from database and displaying it in imgae box ...? I want to retrive an image from database and to display it in a small imagebox...(); f.setTitle("Display Image From database"); Image image = f.getToolkit
forwarding request to a jsp from a filter and displaying image in that jsp
forwarding request to a jsp from a filter and displaying image in that jsp ... correctly, but in login.jsp the image is not displaying. Can you help me in resolving... to this login.jsp from a filter like this request.getRequestDispatcher("login.jsp
How to retrieve image from database
How to retrieve image from database  hi........ How to retrieve image from database when it is stored. I have stored image in postgresql and want... but it retrieves as a string and not complete image can u tel me the conversion
store and retrive image from the database
store and retrive image from the database  please provide me... to store and retreive images from sql database using sql commands -how to store and retreive images from sql database using asp.net/c# thanks in advance
Retrieving the Image from a database Table
Retrieving the Image from a database Table Consider a case where we want... to retrieve the image from the database table. You can do it very easily after... the image from the database table in prepareStatement() method of the Connection
image displaying in java
image displaying in java  how to display an image by using load image button in applet viewer
store & retrive the image from oracle database
store & retrive the image from oracle database  how can i store the image path in tha database & fetch that image from oracle database
displaying List of records from database in a jsp using ajax
displaying List of records from database in a jsp using ajax  Sir, I need to retrieve the records from the database for every 7 seconds and display... data from the database. After getting the response from the servlet am unable
retriving image from database - JSP-Servlet
retriving image from database  how to retrive image from mysql database by using servlet programming  Hi Friend, Please visit the following link: http://www.roseindia.net/servlets/retreiveimage.shtml Thanks
Retrieving Information From Database in JSF Framework - Development process
Retrieving Information From Database in JSF Framework  Requirement... retrieved from database. see how the datatable in select.jsp should be http......... and the connection to database should use via datasource please answer
how to store and retrieve image from database
how to store and retrieve image from database  how to store and retrieve images into database(oracle) and how to retrive images from database using jsp   Here is a jsp code that insert and retrieve image from mysql
To retrieve image from SQL Server Database - Java Server Faces Questions
To retrieve image from SQL Server Database  Sir/Madam, I am trying to retrieve image from SQL Server 2000 database in Visual Web JSF Page using... or in Image Component. please help me in retrieving and displaying image from SQL Server
store and retrive image from database - JDBC
()); } } } For retrieve image from database visit to : http...store and retrive image from database  how to store and retrive an image in database using java?  Hi friend, Code for store image
How to copy an jpeg image from one folder to other folder using jsp
How to copy an jpeg image from one folder to other folder using jsp  How to copy an image from one folder to another folder using jsp
Displaying image using jsp and spring.
Displaying image using jsp and spring.  how to display an image stored in WEB-INF/images folder on the browser using jsp and spring
displaying image in awt - Java Beginners
displaying image in awt  Hi All, I have downloaded the code to display image using awt from here and when I execute the code I am getting... found : java.awt.Image required: Image image = tool.getImage("D
how we retrieve image from database
how we retrieve image from database  my code is:- $search=$_POST... from mysql database: <?php mysql_connect("localhost","username","password... not connect to Database"); $query = "SELECT content,size,type FROM upload WHERE id=1
How to copy an jpeg image from one folder to other folder using jsp
How to copy an jpeg image from one folder to other folder using jsp  hello, i am creating photo gallery where from admin side i allow admin to browse... be in my image folder...so,How to copy an jpeg image from one folder to other
Insert image from user using and save in database
Insert image from user using and save in database  when i am trying to upload a image from user and trying to save into oracle9i database...){e.printStackTrace();} } %> 3)For oracle database, use BLOB datatype for image