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 !!!!!!!!!!!!!!! !!!!!!!!!!!
1 2986 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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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
|
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...
| |
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...
|
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....
|
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.
|
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">
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |