473,396 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to retrive image file from MS access database and display this in another JSPpage

How to retrive image file from MS access database and display this in another JSPpage
--------------------------------------------------------------------------------

This is my Jsp code for image upload in database:

-----------Upload.jsp----------------
<html>

<head>
<title>Account Details </title>
</head>
<body bgproperties="fixed" bgcolor="#CCFFFF">
<form method="POST" action="UploadPicture.jsp" enctype="multiform/form-data">

<%! int update=0; %>

<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.*" %>
<%@ page import="java.sql.Date" %>
<%@ page import="java.io.*"%>

<%@ page language = "java" %>

<%
try
{
String ct="3";
String path;

File image=new File(request.getParameter("upload"));
path=request.getParameter("upload");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:itPlusElect ronics","","");

PreparedStatement pstmt=con.prepareStatement("insert into graphics values(?,?,?)");
pstmt.setString(2,path);
pstmt.setString(3,ct);

InputStream is=new FileInputStream(path);
pstmt.setBinaryStream(1, is, (int)(image.length()));
int s=pstmt.executeUpdate();
if(s>0)
{
out.println("Uploaded");
}
else
{
%>
unsucessfull
<%}
is.close();
pstmt.close();
}
catch(Exception e)
{
}%>
</p>

<p><br>
<img src="UploadedPicture.jsp">image</img>

<p></p>
</form>
</body>
</html>

-------------------------------------------------------------
My database name is itPlusElectronics and the table name is "graphics".
I have seen as a result of the above code that the image is stored in database as "Long binary data". and database table is look like as follows-------
picture path id
Long binary data D:\AMRIT\1-1-Picture.jpg 3

------------------------------------------------------------------------------
To retrive and display i use this JSP code as--

------------------------UploadedPicture.jsp------------------------------

<html>

<head>
<title>Account Details </title>
</head>
<body bgproperties="fixed" bgcolor="#CCFFFF">

<%! int update=0; %>

<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.*" %>

<%@ page import="java.io.*"%>
<%@ page language = "java" %>
<%@page import="javax.servlet.ServletOutputStream"%>

<%

try
{


String path;
path=request.getParameter("upload1");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:itPlusElect ronics","","");

PreparedStatement pst = con.prepareStatement("SELECT * FROM graphics WHERE id ='3'");
// pst.setString(3, id);
ResultSet rs = pst.executeQuery();
path=rs.getString("path");
if(rs.next()) {


byte[] bytearray = new byte[4096];
int size=0;
InputStream sImage;
sImage = rs.getBinaryStream(1);
response.reset();
response.setContentType("image/jpeg");
response.addHeader("Content-Disposition","filename=path");
while((size=sImage.read(bytearray))!= -1 )
{
response.getOutputStream().write(bytearray,0,size) ;
}
response.flushBuffer();
sImage.close();
rs.close();
}

}
catch(Exception e)
{
}
%>


</body>
</html>

------------------------------------------------------------------------------
Now after browsing a jpg image file from client side and pressing submit button ;
I am unable display the image in the Upload.jsp file.Though I use
<img src="UploadedPicture.jsp">image</img> HTML code in Upload.jsp
file .

Now I am unable to find out the mistakes which is needed for displaying the picture in the Upload.jsp page..
If any one can help with the proper jsp code to retrive and display the image ,please please help me !!!!!!!!!!!!!!!!!!!!!!!!!!
Dec 29 '07 #1
1 2960
ajos
283 100+
How to retrive image file from MS access database and display this in another JSPpage
--------------------------------------------------------------------------------

This is my Jsp code for image upload in database:

-----------Upload.jsp----------------
<html>

<head>
<title>Account Details </title>
</head>
<body bgproperties="fixed" bgcolor="#CCFFFF">
<form method="POST" action="UploadPicture.jsp" enctype="multiform/form-data">

<%! int update=0; %>

<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.*" %>
<%@ page import="java.sql.Date" %>
<%@ page import="java.io.*"%>

<%@ page language = "java" %>

<%
try
{
String ct="3";
String path;

File image=new File(request.getParameter("upload"));
path=request.getParameter("upload");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:itPlusElect ronics","","");

PreparedStatement pstmt=con.prepareStatement("insert into graphics values(?,?,?)");
pstmt.setString(2,path);
pstmt.setString(3,ct);

InputStream is=new FileInputStream(path);
pstmt.setBinaryStream(1, is, (int)(image.length()));
int s=pstmt.executeUpdate();
if(s>0)
{
out.println("Uploaded");
}
else
{
%>
unsucessfull
<%}
is.close();
pstmt.close();
}
catch(Exception e)
{
}%>
</p>

<p><br>
<img src="UploadedPicture.jsp">image</img>

<p></p>
</form>
</body>
</html>

-------------------------------------------------------------
My database name is itPlusElectronics and the table name is "graphics".
I have seen as a result of the above code that the image is stored in database as "Long binary data". and database table is look like as follows-------
picture path id
Long binary data D:\AMRIT\1-1-Picture.jpg 3

------------------------------------------------------------------------------
To retrive and display i use this JSP code as--

------------------------UploadedPicture.jsp------------------------------

<html>

<head>
<title>Account Details </title>
</head>
<body bgproperties="fixed" bgcolor="#CCFFFF">

<%! int update=0; %>

<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.*" %>

<%@ page import="java.io.*"%>
<%@ page language = "java" %>
<%@page import="javax.servlet.ServletOutputStream"%>

<%

try
{


String path;
path=request.getParameter("upload1");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:itPlusElect ronics","","");

PreparedStatement pst = con.prepareStatement("SELECT * FROM graphics WHERE id ='3'");
// pst.setString(3, id);
ResultSet rs = pst.executeQuery();
path=rs.getString("path");
if(rs.next()) {


byte[] bytearray = new byte[4096];
int size=0;
InputStream sImage;
sImage = rs.getBinaryStream(1);
response.reset();
response.setContentType("image/jpeg");
response.addHeader("Content-Disposition","filename=path");
while((size=sImage.read(bytearray))!= -1 )
{
response.getOutputStream().write(bytearray,0,size) ;
}
response.flushBuffer();
sImage.close();
rs.close();
}

}
catch(Exception e)
{
}
%>


</body>
</html>

------------------------------------------------------------------------------
Now after browsing a jpg image file from client side and pressing submit button ;
I am unable display the image in the Upload.jsp file.Though I use
<img src="UploadedPicture.jsp">image</img> HTML code in Upload.jsp
file .

Now I am unable to find out the mistakes which is needed for displaying the picture in the Upload.jsp page..
If any one can help with the proper jsp code to retrive and display the image ,please please help me !!!!!!!!!!!!!!!!!!!!!!!!!!
Hi,
how about this link here image servlet . Im sorry i havent seen your problem exactly. But the link here serves a image from a path outside of the web container.
Haaaapy New Year :)
regards,
ajos
Dec 31 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Wally | last post by:
I am trying to display images from an Access 2000 database and I get an error "Invalid Parameter Used" when I execute the code line "picBLOB.Image = Image.FromStream(stmBLOBData)" in my Visual...
3
by: coolsti | last post by:
I need some help here. I am making an application which allows a user to look at a series of picture files one at a time, and enter the outcome of various visual tests to a database. The...
3
by: Ken | last post by:
I have a win 2000 database of autographs and scanned photos. They are in the SAME directory. In the table, my "ImagePath" text field shows JUST the image name (i.e. "blank.jpg"). I have an image...
1
by: Eric Keung | last post by:
Hi all, my case is I want to get an image from access database and I just know it's "OLE object" field type at access I also don't know how to insert it into access here is my code and it just...
2
by: Wayne Wengert | last post by:
I am trying to build an ASP.NET application which includes the capability to allow users to save pictures to a SQL Server 2000 database table and then later to display selected photos (usually JPG...
2
by: Terry | last post by:
Any .dll or COM+ for .Net can help me retrive data from a Access file? The table contain several columns and the last one is a container which I store Article; because each article is a little bit...
7
by: needin4mation | last post by:
Hi, I have an Access 2002 - 2003 database. I am using Access 2003. Whenever I link an image all it shows is the filename. Not the image. Other versions of Access can link the image just fine. ...
0
nehashri
by: nehashri | last post by:
hi, I need one help regarding Asp with MsAccess database. Problem. ======== i want to retrive stored image from the MSAccess database using asp.
2
by: amritranjan | last post by:
This is my Jsp code for image upload in database: -----------Upload.jsp---------------- <html> <head> <title>Account Details </title> </head> <body bgproperties="fixed" bgcolor="#CCFFFF">...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.