Upload Image and save in database using jsp-servlet mvc
Here is my code..
In jsp ...
<form name=frm method="post" action="Device">
<table>
<tr><TD ><B>Upload Image</B></TD>
<td><input type="file" name="Image" size="20" value=""></TD>
</tr>
<tr>
<td><input type="submit" height="30" width="62"> </td>
</tr>
</form>
<form name=frm method="post" action="Device">
<table>
<tr><TD ><B>Upload Image</B></TD>
<td><input type="file" name="Image" size="20" value=""></TD>
</tr>
<tr>
<td><input type="submit" height="30" width="62"> </td>
</tr>
In servlet...
try
{
String strpath=request.getParameter("Image");
String filepath=strpath.substring(strpath.lastIndexOf("\\")+1);
File imgfile = new File(strpath);
FileInputStream fin = new FileInputStream(imgfile);
Connection connection=null;
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
PreparedStatement pre = connection.prepareStatement("insert into uploadimage(image,image_name,image_length) values(?,?,?)");
pre.setBinaryStream(1,fin,(int)imgfile.length());
pre.setString(2,filepath);
pre.setLong(3,imgfile.length());
pre.executeUpdate();
pre.close();
String L_url1=response.encodeRedirectURL("Device.jsp");
response.sendRedirect(L_url1);
}
catch(Exception ex){
System.out.println("Exception in InsertImage : "+ex.getMessage());
}
}
but throws exception
(The system cannot find the file specified)
How to rectify..
View Answers
Ads
Related Tutorials/Questions & Answers:
Advertisements
Image upload in mysql database using jsp servlet
Image 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
Jsp using mvc - JSP-Servlet
Jsp using mvc hi
I have written
using mvc2 architecture, i have written logic in java ,i want to print a message on the form stating the the values... closely together.
Read
MVC 2 Pattern in Struts2 in details and visit
edit database using jsp and servlet
edit
database using jsp and servlet I am creating a website
using jsp and servlets that is used to view houses from a
database. I want to be able... information from the
database in the textboxes. Please help me to display
Insert image from user using and save in database
Insert
image from user
using and
save in database when i am trying to
upload a
image from user and trying to
save into oracle9i
database...){e.printStackTrace();}
}
%>
3)For oracle
database, use BLOB datatype for
image
fetch record from oracle database using jsp-servlet?
fetch record from oracle
database using jsp-
servlet? how can i fetch data from oracle
database by
using jsp-
servlet. i'm
using eclipse, tomcat server and oracle
database and creating
jsp pages and also
using servlet
upload image to database
upload image to database i am try to
upload image to MySql
database using netbeans.
when
jsp execute it return no error. but also data does inserted in
database. i am
using blob datatype and preopared statement
upload image using JSP Hibernate
upload image using JSP Hibernate sir,
I want to take
image from user and
save to
database(MYSQL)
using Hibernate and
JSP
Thanks in advance
image display - JSP-Servlet
image display how to display
image that store in mysql
database... column have BLOB datatype.... Hi Friend,
Please visit the following link:
http://www.roseindia.net/
jsp/retrieve-image.shtml
Thanks
Uploading an image into the table - JSP-Servlet
to the specified
database. */
psmnt = connection.prepareStatement
("insert into
save_
image...Uploading an
image into the table how to
upload an
image... {
System.out.println("unsucessfull to
upload image.");
}
}
// catch if found
Multiple image upload using JSP
Multiple
image upload using JSP I have written a code to
upload the multiple images
using jsp, but when I execute this code, it throws Corrupt form... = getServletContext().getRealPath("/") +
> File.separator +
>
UPLOAD_DIRECTORY;/*
save