473,836 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

3 New Member
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>Accoun t Details </title>
</head>
<body bgproperties="f ixed" bgcolor="#CCFFF F">
<form method="POST" action="UploadP icture.jsp" enctype="multif orm/form-data">

<%! int update=0; %>

<%@ page import="java.ut il.*" %>
<%@ page import="java.sq l.*" %>
<%@ page import="java.te xt.*" %>
<%@ page import="java.sq l.Date" %>
<%@ page import="java.io .*"%>

<%@ page language = "java" %>

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

File image=new File(request.ge tParameter("upl oad"));
path=request.ge tParameter("upl oad");
Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
Connection con = DriverManager.g etConnection("j dbc:odbc:itPlus Electronics","" ,"");

PreparedStateme nt pstmt=con.prepa reStatement("in sert into graphics values(?,?,?)") ;
pstmt.setString (2,path);
pstmt.setString (3,ct);

InputStream is=new FileInputStream (path);
pstmt.setBinary Stream(1, is, (int)(image.len gth()));
int s=pstmt.execute Update();
if(s>0)
{
out.println("Up loaded");
}
else
{
%>
unsucessfull
<%}
is.close();
pstmt.close();
}
catch(Exception e)
{
}%>
</p>

<p><br>
<img src="UploadedPi cture.jsp">imag e</img>

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

-------------------------------------------------------------
My database name is itPlusElectroni cs 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>Accoun t Details </title>
</head>
<body bgproperties="f ixed" bgcolor="#CCFFF F">

<%! int update=0; %>

<%@ page import="java.ut il.*" %>
<%@ page import="java.sq l.*" %>
<%@ page import="java.te xt.*" %>

<%@ page import="java.io .*"%>
<%@ page language = "java" %>
<%@page import="javax.s ervlet.ServletO utputStream"%>

<%

try
{


String path;
path=request.ge tParameter("upl oad1");
Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
Connection con = DriverManager.g etConnection("j dbc:odbc:itPlus Electronics","" ,"");

PreparedStateme nt pst = con.prepareStat ement("SELECT * FROM graphics WHERE id ='3'");
// pst.setString(3 , id);
ResultSet rs = pst.executeQuer y();
path=rs.getStri ng("path");
if(rs.next()) {


byte[] bytearray = new byte[4096];
int size=0;
InputStream sImage;
sImage = rs.getBinaryStr eam(1);
response.reset( );
response.setCon tentType("image/jpeg");
response.addHea der("Content-Disposition","f ilename=path");
while((size=sIm age.read(bytear ray))!= -1 )
{
response.getOut putStream().wri te(bytearray,0, size) ;
}
response.flushB uffer();
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="UploadedPi cture.jsp">imag e</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 3383
ajos
283 Contributor
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>Accoun t Details </title>
</head>
<body bgproperties="f ixed" bgcolor="#CCFFF F">
<form method="POST" action="UploadP icture.jsp" enctype="multif orm/form-data">

<%! int update=0; %>

<%@ page import="java.ut il.*" %>
<%@ page import="java.sq l.*" %>
<%@ page import="java.te xt.*" %>
<%@ page import="java.sq l.Date" %>
<%@ page import="java.io .*"%>

<%@ page language = "java" %>

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

File image=new File(request.ge tParameter("upl oad"));
path=request.ge tParameter("upl oad");
Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
Connection con = DriverManager.g etConnection("j dbc:odbc:itPlus Electronics","" ,"");

PreparedStateme nt pstmt=con.prepa reStatement("in sert into graphics values(?,?,?)") ;
pstmt.setString (2,path);
pstmt.setString (3,ct);

InputStream is=new FileInputStream (path);
pstmt.setBinary Stream(1, is, (int)(image.len gth()));
int s=pstmt.execute Update();
if(s>0)
{
out.println("Up loaded");
}
else
{
%>
unsucessfull
<%}
is.close();
pstmt.close();
}
catch(Exception e)
{
}%>
</p>

<p><br>
<img src="UploadedPi cture.jsp">imag e</img>

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

-------------------------------------------------------------
My database name is itPlusElectroni cs 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>Accoun t Details </title>
</head>
<body bgproperties="f ixed" bgcolor="#CCFFF F">

<%! int update=0; %>

<%@ page import="java.ut il.*" %>
<%@ page import="java.sq l.*" %>
<%@ page import="java.te xt.*" %>

<%@ page import="java.io .*"%>
<%@ page language = "java" %>
<%@page import="javax.s ervlet.ServletO utputStream"%>

<%

try
{


String path;
path=request.ge tParameter("upl oad1");
Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
Connection con = DriverManager.g etConnection("j dbc:odbc:itPlus Electronics","" ,"");

PreparedStateme nt pst = con.prepareStat ement("SELECT * FROM graphics WHERE id ='3'");
// pst.setString(3 , id);
ResultSet rs = pst.executeQuer y();
path=rs.getStri ng("path");
if(rs.next()) {


byte[] bytearray = new byte[4096];
int size=0;
InputStream sImage;
sImage = rs.getBinaryStr eam(1);
response.reset( );
response.setCon tentType("image/jpeg");
response.addHea der("Content-Disposition","f ilename=path");
while((size=sIm age.read(bytear ray))!= -1 )
{
response.getOut putStream().wri te(bytearray,0, size) ;
}
response.flushB uffer();
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="UploadedPi cture.jsp">imag e</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
1966
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 Basic .Net application. I have researched MSDN for help and found the example article 321900 (see below) and set up a test and everything works fine when I use SQL Server 2000 but when I modify the code and use data from Access 2000 using an...
3
6765
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 application is based on mysql and php on a remote server, and is accessed by the user via a web browser, primarilly IE. The image file names are built up by the server side php scripts, and so a URL for the image file is created, but the file itself is...
3
4041
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 field that links to the ImagePath field. But it does not display in the form. I go in and delete the image field and add it back in and link it to the "blank.jpg" file (its a dummy jpg that says "Not Avail"). Then I make sure it is linked and not...
1
2947
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 can display a invalid image try dim strConn as string strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & server.mappath
2
2475
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 files). I found some sample code via a google search which showed how to upload a jpg file using ASP (HtmlInputFile) and save it in an Access database and I've tried to adapt that to work with ASP.NET/SQL Server and I am able to get the file data...
2
1667
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 huge, so when I store it, it ask me if I want to pack it (the article) into a object then I click 'Yes'. But now I need to retrive data from the file and show it by datagrid, and now I don't know what kind of data type it is (when I click it, it...
7
10172
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. The properties look the same whether I use XP or 2003 versions of Office. If I take an earlier version of Access and link the image, it puts the image. I can also see the image in 2003. If I link the image using 2003 it only shows the filename....
0
1664
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
2818
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"> <form method="POST" action="UploadPicture.jsp" enctype="multiform/form-data">
0
9825
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9673
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10859
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10560
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10260
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6984
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.