File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes I hot error time of file uploading in servlet/jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "I hot error time of file uploading in servlet/jsp" Watch "I hot error time of file uploading in servlet/jsp" New topic

I hot error time of file uploading in servlet/jsp

Arjun Palanichamy
Ranch Hand

Joined: Jul 15, 2006
Posts: 51

I had use servlet and jsp for file upload processing, but it's getting some error, i am here paste the my code.

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import com.oreilly.servlet.MultipartRequest;
import com.oreilly.servlet.multipart.FilePart;
import com.oreilly.servlet.multipart.MultipartParser;
import com.oreilly.servlet.multipart.Part;

import datasourcefactory.DatabaseConnectionFactory;

public class Upload_Ad_imageDAO {

private static final Logger log = Logger

Connection con = null;

PreparedStatement pst = null;

ResultSet rs = null;

boolean state = false;

public void writeImages(HttpServletRequest req,String ad_id)

throws SQLException , IOException {
String email = null;
HttpSession session = req.getSession(true);

email = (String) session.getAttribute("email");

MultipartRequest multi =

new MultipartRequest(req,ad_id);

Enumeration files = multi.getFileNames();
while (files.hasMoreElements()) {

String name = (String)files.nextElement();

String filename = multi.getFilesystemName(name);

String type = multi.getContentType(name);

// File f = multi.getFile(name);

File f = new File("X:/work/Uno_Car/web/advertise_images/"+ad_id+".gif");

//out.println("name: " + name);;

//out.println("filename: " + filename);;

//out.println("type: " + type);;
if (f != null) {
String s = f.getName();
try {
con = DatabaseConnectionFactory.getInstance().getDBConnection();
pst = con.prepareStatement("update ad_detail set file_name=? where email=?");
pst.setString(1, ad_id);
//pst.setString(2, type);
pst.setString(2, email);
pst.executeUpdate();;;"Image Sucessfuly Uploaded");
state = true;
} catch (SQLException e) {
} finally {
if (pst != null) {
if (con != null) {


what is wrong here. i not write and upload the image.

please any can help me solve this problem.

Thanks in Advance.
Arjun Palanichamy.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42959
If there's an exception, post the full stack trace. If there's some other error, describe in detail what is happening.
Veeresh Hosur
Ranch Hand

Joined: Dec 18, 2007
Posts: 32
I think the problem is in this line

<Code> File f = new File("X:/work/Uno_Car/web/advertise_images/"+ad_id+".gif");</code>

so please check it out or else post your full track trace.

I agree. Here's the link:
subject: I hot error time of file uploading in servlet/jsp
It's not a secret anymore!