How to insert image path and image name into oracle database and image into folder using jsp?
November 5, 2012 at 12:37 PM
Here is a code that insert image path and name into mysql database and image into folder.
1)form.jsp:
<%@ page language="java" %>
<HTML>
<FORM ENCTYPE="multipart/form-data" ACTION="uploadFile.jsp" METHOD=POST>
<center>
<table border="0" bgcolor=#ccFDDEE>
<tr>
<center><td colspan="2" align="center"><B>UPLOAD THE FILE</B><center></td>
</tr>
<tr><td colspan="2" align="center"> </td></tr>
<tr><td><b>Choose the file To Upload:</b></td>
<td><INPUT NAME="file" TYPE="file"></td>
</tr>
<tr><td colspan="2" align="center"> </td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="Send File"> </td></tr>
<table>
</center>
</FORM>
</HTML>
2)uploadFile.jsp:
<%@ page import="java.io.*,java.sql.*" %>
<%
String saveFile="";
String contentType = request.getContentType();
if((contentType != null)&&(contentType.indexOf("multipart/form-data") >= 0)){
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while(totalBytesRead < formDataLength){
byteRead = in.read(dataBytes, totalBytesRead,formDataLength);
totalBytesRead += byteRead;
}
String file = new String(dataBytes);
saveFile = file.substring(file.indexOf("filename=\"") + 10);
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
int pos;
pos = file.indexOf("filename=\"");
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
File ff = new File("C:/UploadedFiles/"+saveFile);
FileOutputStream fileOut = new FileOutputStream(ff);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();
%><br><table border="2"><tr><td><b>You have successfully upload the file:</b>
<%out.println(saveFile);%></td></tr></table>
<%
Connection connection = null;
String connectionURL = "jdbc:mysql://localhost:3306/roseindia";
PreparedStatement psmnt = null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root", "root");
psmnt = connection.prepareStatement("insert into file(file_name,file_path) values(?,?)");
psmnt.setString(1, ff.getName());
psmnt.setString(2, ff.getPath());
int s = psmnt.executeUpdate();
if(s>0){
System.out.println("Uploaded successfully !");
}
else{
System.out.println("Error!");
}
}
catch(Exception e){
e.printStackTrace();
}
}
%>
Related Tutorials/Questions & Answers:
Advertisements
Full path of image to save it in a folderFull
path of
image to save it in a folder Sir ,I am trying to upload a file but only sends file
name as parameter.
I want a code that would help me to find that
image path &upload it as well.
I am just a beginner in
jsp change the name of the image after uploading the imagechange the
name of the
image after uploading the image my form consists of a textbox and uploading the image.after uploading the
image i want to change the
name of the
image with the content of the textbox before saving
Image upload in mysql database using jsp servletImage upload in mysql
database using jsp servlet Hello, I need code to insert
image in mysql
database, I have seen the code which is already in your portal but it is not inserting
image into
database it save in the
folder inserting an path of an image in database - JDBC to save it in
folder..but can you plz tell me how an the full
path of
image can... infolder with unique
name and in
database its whole
path get inserted
code...inserting an
path of an
image in database hello
kindly help related
display image using jspdisplay
image using jsp display
image using jsp and phonegap on emulator of eclipse
Here is a simple
jsp code that displays an
image on browser.
<%@ page import="java.io.*" %>
<%@page contentType="
image/gif
upload image using JSP Hibernateupload
image using JSP Hibernate sir,
I want to take
image from user and save to
database(MYSQL)
using Hibernate and
JSP
Thanks in advance
Delete image from folder - JSP-ServletDelete
image from folder Hi
Thanks Rajnikant
to given me reply
i am not storing my
image in db just userid comming from db
means my
image name like : Pie(userid).png
which alocated in my server
folder
when
Delete image from folder - JSP-Servlet. that
image name based on user id and that
image is going to on
folder in server after...Delete
image from folder Dear All,
i used some coding... creating a new png
image. in my project if two user will be login same time meanse
image save to folder in java folder and that
path stored into
database, for furhter retrivation.
Please guide me...
image save to
folder in java Hi,
I am working with java. In my application i want to give facility to user to add and change
image. I use open
Uploading image using jspUploading
image using jsp how to upload
image using jsp. Already i... that
image file ...
I want know that solution
using by u...
Thanks,
P.S.N.
Here is a
jsp code that upload
image and display it on the browser.
1
How to store and retrieve image from database in JSP?How to store and retrieve
image from
database in
JSP? Hi,
In one... and retrieve
image from
database in
JSP?
Thanks
HI,
You can use... the
image. Check this example:
Retrieve
image from
database using Servlet.
Thanks
how to store image upload path to mssql databasehow to store
image upload
path to mssql database hi there!!,
i need help in storing the
image upload
path into the
database. basically i just use file select to upload the
image from
jsp to
database. however when i click submit
how to store image upload path to mssql databasehow to store
image upload
path to mssql database hi there!!,
i need help in storing the
image upload
path into the
database. basically i just use file select to upload the
image from
jsp to
database. however when i click submit
how to store image upload path to mssql databasehow to store
image upload
path to mssql database hi there!!,
i need help in storing the
image upload
path into the
database. basically i just use file select to upload the
image from
jsp to
database. however when i click submit
how to store image upload path to mssql databasehow to store
image upload
path to mssql database hi there!!,
i need help in storing the
image upload
path into the
database. basically i just use file select to upload the
image from
jsp to
database. however when i click submit
How to retrieve image from mysql database in JSP?How to retrieve
image from mysql
database in
JSP? Hi,
I need
JSP... to retrieve
image from mysql
database in
JSP?
Thanks
Hi,
You can write SQL query to find the data from
database and get the
image from resultset
using How to retrieve blob image from database in JSP?How to retrieve blob
image from
database in
JSP? Hello,
JSP is used... the blog
image from
database.
How to retrieve blob
image from
database in
JSP?
Hi,
Please check the tutorial Retrieve
image from
database using image upload&download using jsp - JSP-Servletimage upload&download
using jsp can any one help in writing
jsp for upload and download of images from
database.. Hi Friend,
Please visit the following links:
http://www.roseindia.net/
jsp/fileupload.shtml
http
Fetching image from database name in
database so, now how can i display that
image using JSP or HTML page(is it possible to display
using tag
using concatination).
image path i have stored in
database is:E:\1003\54175\20110407121554
image name i have stored
image is display from path of mysql databaseimage is display from
path of mysql database <%@ page import="java.io.,java.sql.,java.util.zip.*" %>
<%
String saveFile="";
String..._
path) values(?)");
psmnt.setString(1, ff.getPath());
int s = psmnt.executeUpdate
image in databaseimage in database how to set
image in
database and retrieve it
using servlet(java)in msaccess
image in jsp - JSP-Servletimage in jsp i m storing
path of
image in my
database.. but when i m trying to display
image using that
path image is not getting... i m storing
path like c:\
image\a.jpg ... and i m
using tag... how to get