Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with uploading images using Jsp

    Hi,


    My Requirement is to upload the images into database through jsp. For that i write a code .And it works fine .But in that File imgfile = new File("C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/test/Blue.jpg"); instead of that i used File imgfile = new File("Blue.jpg"); like that it didn't work. When we browse that image from local system it automatically takes like Blue.jpg and didn't take the full path.
    So i got the error as " Blue.jpg not found". Please tell the solution how can i resolve my problem.


    Code:
    <%@ page import="java.sql.*" %>
    <%@ page import="java.io.*"%>
    <%
    String connectionURL = "jdbc:mysql://localhost:3306/";
    String dbName = "user_register";
    Connection connection = null;
    PreparedStatement pre=null;
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    connection = DriverManager.getConnection(connectionURL+dbName, "root", "root");
    out.println("connection");
    File imgfile = new File("C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/test/Blue.jpg");
     out.println("reerr");
     FileInputStream fin = new FileInputStream(imgfile);
      pre = connection.prepareStatement("insert into Image values(?,?,?)");
      pre.setInt(1,3);
    			pre.setString(2,"new");
    			pre.setBinaryStream(3,fin,(int)imgfile.length());
    			pre.executeUpdate();
    			out.println("Inserting Successfully!");
    			%>

  • #2
    Regular Coder lokeshshettyk's Avatar
    Join Date
    Aug 2008
    Location
    On the way to the moon!
    Posts
    157
    Thanks
    5
    Thanked 20 Times in 20 Posts
    You need to be a little more clear about your problem, would be tough to deal with otherwise.

    In your code, you have used
    Code:
    File imgfile = new File("C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/test/Blue.jpg");
    Did you mean that you were trying to use
    Code:
    File imgfile = new File("Blue.jpg");
    and it did not work?

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi,

    yes exactly i trying like that .plz tell the solution for that

  • #4
    Regular Coder lokeshshettyk's Avatar
    Join Date
    Aug 2008
    Location
    On the way to the moon!
    Posts
    157
    Thanks
    5
    Thanked 20 Times in 20 Posts
    File imgfile = new File("Blue.jpg"); - this would work only if the image is stored directly under the root folder (something like /usr/local/apache/htdocs/blue.jpg).
    say for ex: if your root folder is C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/ and assume that the image is stored under a folder named 'images' then the path should be File imgfile = new File("/images/blue.gif"); else your program will not find the file specified.

    Hope this helps


    Cheers


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •