Uploading an Image to a Database using JSP

By: Mahesh Emailed: 1727 times Printed: 2328 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

This jsp Page is Uploding The Image into Database using MultipartRequest class FileSystem concepts and ByteArray.

<%@ page import="java.sql.*,java.io.*,java.util.*,com.oreilly.servlet.MultipartRequest,com.microsoft.jdbc.sqlserver.SQLServerDriver;"%>

/* The Following Code is Used To Insert An Image Into Database */

String filename="";
//Download com.oreilly package

MultipartRequest multi= new MultipartRequest(request,".",5*1024*1024);
Enumeration files=multi.getFileNames();
File f=null;
String name=(String)files.nextElement();
String type=multi.getContentType(name);
System.out.println("The File is "+f);
Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver;databasename="xxx","username","password");
Statement stmt = con.createStatement();
InputStream is = new FileInputStream(f);
byte b[]=new byte[is.available()];
String sql = "INSERT into photo_test (\"Photo\") values('" + b + "')";
}catch(Exception e)
out.println("The Image is Added into Database");

JSP Home | All JSP Tutorials | Latest JSP Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.

Bookmark and Share


1. View Comment


View Tutorial          By: naresh at 2012-08-04 11:19:03
2. View Comment

good for learners

View Tutorial          By: muhammed at 2012-11-20 10:38:28
3. View Comment

feel happy but i want to database tables also

View Tutorial          By: sisira at 2013-06-05 13:26:51
4. View Comment

how to code for images hitting in jsp like google images...

please tell any hints... please

View Tutorial          By: Kumaravel at 2014-08-06 11:23:08

Your name (required):

Your email(required, will not be shown to the public):

Your sites URL (optional):

Your comments:

More Tutorials by Mahesh
Floating point precision in PHP
Uploading an Image to a Database using JSP

More Tutorials in JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: `java.net.BindException: Permission denied <null>:80
JSP Alert Example
JSP CheckBox Example
Uploading an Image to a Database using JSP
Uploading a file to a server using JSP
A JSP page that gets properties from a bean
The page Directive in JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Declarations in JSP
Scriptlets and Expressions in JSP
Tag Libraries in JSP
The Request Object in JSP
The Response Object in JSP
The Out Object in JSP
The Session Object in JSP

More Latest News
Most Viewed Articles (in JSP )
JSP Example to connect to MS SQL database and retrieve records
JSP CheckBox Example
What are the different scopes in JSP?
JSP Alert Example
Sending Email using JSP
Automatically Refreshing a JSP
JSP Program for display Date
Comparison operators in JSP
The Advantages of JSP
Arithmetic Evaluation Using the Expression Language in JSP
The Request Object in JSP
Uploading an Image to a Database using JSP
Tags using in jsp
Introduction to JSP expression language
Disabling Scriptlets in JSP using web.xml
Most Emailed Articles (in JSP)
Debugging Servlets
The JSP Program running first Time.
Syntax For JSP Declaratives
Combining Scriptlets with HTML
Form processing in JSP
Password Object
Server-side plug-Ins
The Web User's Perspective
Disabling Scriptlets in JSP using web.xml
JSP Example to connect to MS SQL database using Tomcat Connection Pool
The Session Object in JSP
The Application Object in JSP
JSP CheckBox Example
What is JSP?
Server Side Programming