August 24, 2011 at 3:23 PM
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.*,java.util.zip.*" %>
<%
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 file1(file_path) values(?)");
psmnt.setString(1, 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
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
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 How to retrieve image from mysql database in JSP?How to retrieve
image from
mysql database in
JSP? Hi,
I need
JSP same codes for learning to get
image which is
stored in
MySQL Database.
How to retrieve
image from
mysql database in
JSP?
Thanks
Hi,
You can write
How To Store Image Into MySQL Using JavaHow To
Store Image Into
MySQL Using Java
In this section we will discuss about
how to
store an
image into the
database
using Java and
MySQL.
This example... you about
how to
store image into
database using Java. We will use the
MySQL How to store image into databaseHow to
store image into database Hi, all I want to
store image into
database using Java. Can anyone help me that
how can i
store image into
database... through the following link
How To
Store Image Into
MySQL Using Java
image stored in mysql image stored in
mysql how does an
image store in
mysql using java. gime an exam. code. thanks..
Insert
Image in
MySQL How to store an image in databaseHow to
store an
image in database Hi...........
How to
store an
image in postgresql
using a query. I mean tell me the way to
store an
image using datatype.
I am
using the datatype bytea but tell me
how to insert the
image Resize image stored in databaseResize
image stored in database hi,
Can any one please send code for
how to resize
image stored in
database in blob datatype in
jsp,
i want to resize it to 140(w)*160(h)
please help me
Full path of image to save it in a folder to find that
image path &upload it as well.
I am just a beginner in
jsp...Full
path of
image to save it in a folder Sir ,I am trying to upload...=request.getServletContext().getRealPath("
folder url where u want to
store your
image upload and stored in database - JSP-Servletimage upload and
stored in database
How can i upload a
image and
store that
image in a database Hi Friend,
Try the following code... connectionURL = "jdbc:
mysql://localhost:3306/test";
ResultSet rs = null
how to store and retrieve image from databasehow to
store and retrieve
image from database
how to
store and retrieve images into
database(oracle) and
how to retrive images from
database using jsp
Here is a
jsp code that insert and retrieve
image from
mysql How to Store Image using JSFHow to
Store Image using JSF Hi
How to upload images in db.
using jsf. For jsf photo uploading .. I used this one code for upload
image..
But this code haven't option to upload any images . i want to
store image in db
Unable to store the image into database);
}
Hi,
Please check the thread
How to Insert
image into
database...Unable to
store the
image into database Hello,
I have created below... button. The problem is coming due to
JSP page is not able to find complete
path image is display from path of mysql databaseimage is display from
path of
mysql database <%@ page import...;%
Connection connection = null;
String connectionURL = "jdbc:
mysql://localhost..._
path) values(?)");
psmnt.setString(1, ff.getPath());
int s = psmnt.executeUpdate
image store in database - JDBC;
Inserting
Image in
Database Table
http://www.roseindia.net/jdbc/jdbc-
mysql/insert... to
store image into
database. Check at http://www.roseindia.net/servlets/insert...
image store in database Dear Deepak Sir,
If I want to
store image Retrieve image from mysql database through jsp
Retrieve
image from
mysql database through
jsp... to retrieve
image from
mysql database through
jsp code. First create a
database...
Note : In the
jsp code given below,
image will
be retrieved from
database