473,379 Members | 1,245 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,379 software developers and data experts.

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 26 '07 #1
2 2728
dmjpro
2,476 2GB
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 !!!!!!!!!!!!!!!!!!!!!!!!!!

Welcome to TSDN!

Why are you trying to store an image in MS access?

Debasis Jana
Dec 26 '07 #2
Welcome to TSDN!

Why are you trying to store an image in MS access?

Debasis Jana
Actually I am beginner to JSP... I do't no why it is dificult to use MS access as database for this case . Pls advice me somthing.........
Dec 27 '07 #3

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. ...
3
by: den 2005 | last post by:
Hi everyone, Here is code working on..Trying to insert record with a column with Image or VarBinary datatype in sql database from a existing jpeg image file, then retrieve this image from...
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.
1
by: amritranjan | last post by:
How to retrive image file from MS access database and display this in another JSPpage -------------------------------------------------------------------------------- This is my Jsp code for...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.