Cannot Upload file from Local Machine

Discussion in 'Software' started by apjustin, May 21, 2008.

  1. apjustin

    apjustin

    Joined:
    May 21, 2008
    Messages:
    1
    Hi,
    I'm facing a problem while trying to upload an image from local machine hard drive to the database in web server using servlet.
    I'm able to upload an image to the database in the local machine !!!!!!
    But the image is not being uploaded to the remote database !!
    The String CouponImage is a local machine path of the image like E:\Coupons\Coupon1.jpg . It's not being accepted.
    Please help me. I'm new to servlet programming.
    I'm using the following code

    public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
    {
    res.setContentType("text/html");
    try{
    Connection connection = null;
    FileInputStream fis = null;
    PreparedStatement preparedStatement =null;
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    connection = DriverManager.getConnection ("jdbc:mysql://localhost/MobileCoupons",username,password);
    String CouponImage = req.getParameter("upload");
    String query = "INSERT INTO Coupondata(CouponImage) VALUES (?)";
    preparedStatement = connection.prepareStatement(query);
    File file = new File(CouponImage);
    fis = new FileInputStream(file);
    preparedStatement.setBinaryStream(3, fis, (int) file.length());
    preparedStatement.execute();
    connection.commit();
    connection.close();
    fis.close();
    }
    }
     
    apjustin, May 21, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dwåcôn
    Replies:
    7
    Views:
    53,838
    Toolman Tim
    Sep 14, 2005
  2. dee
    Replies:
    2
    Views:
    10,667
  3. bilal0khalid
    Replies:
    2
    Views:
    916
    bilal0khalid
    Mar 24, 2008
  4. Jagadeeshg
    Replies:
    0
    Views:
    917
    Jagadeeshg
    Mar 2, 2009
  5. sr19

    Vist Machine cannot see XP machine on Network

    sr19, Jan 17, 2010, in forum: Wireless Networking
    Replies:
    1
    Views:
    1,540
    Jack [MVP-Networking]
    Jan 19, 2010
Loading...

Share This Page