• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get the file path from html code to Java

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone, I'm trying to storing the user profile image into database.....that's why I'm develop the html code for browse and taking user image path into text field in html...NOW I'm stuct into that user path how can retrieve from html code to java code for Storing that path image file into DB........Please help me out of this......

HTML code:-

<tr>
<td class="blog_text">File to Upload:</td>
<td>
<input size=38 TYPE="file" NAME="file">
</td>
</tr>
<td>
<input type=hidden name="serial_number" value="1234567890">
</td>
<td><input type="submit" name="button" id="button" value="Post" style="height: 25px; width:100px" action="SubmitData.action"/>
<input type="Reset" name="Reset" id="Reset" value="Reset" style="height: 25px; width:100px"/></td>


Java code:-- For using preparedstatement for storing user data into DB:-

Class.forName(DRIVER);
con1 = DriverManager.getConnection(URL+DB_Name,USERNAME,PASSWORD);
PreparedStatement ps = con1.prepareStatement("insert into post_detail values(?,?,?,?,?,?)");
con1.setAutoCommit(true);
System.out.println("commited Successfully ");
ps.setInt(1,bn2.getPost_id());
ps.setString(2, bn2.getUser_name());
ps.setString(3, bn2.getTitle());
ps.setString(4, bn2.getComment());
ps.setInt(5, bn2.getRating());
FileInputStream fin = new FileInputStream("E:/WORK/img/back.jpg");

ps.setBinaryStream(6,fin,fin.available());
status = ps.executeUpdate();
ps.close();
con1.close();


Thank You in Advance
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sushant Gandhi wrote:NOW I'm stuct into that user path how can retrieve from html code to java code for Storing that path image file into DB........Please help me out of this......


We'd like to, but I, for one, still don't know what you're asking:
  • Do you not know what happens when you hit the 'submit' button?
  • Do you not know how to extract that info from the Post? You certainly appear to have written several methods for it.

  • I think it would be much better if you supplied the relevant code from your 'bn2' object (please don't just dump it all on us).

    Also: if that is where your problem is, my advice would be to forget all about the database access for now.

    Run your program and print out the values returned by your web page as Strings, and make absolutely sure that they are exactly what you want every single time you run it before you write one line of database access.

    Alternatively, if you know that 'bn2' is NOT the cause of your problems, print out the values that are being substituted into your PreparedStatement before you run it.

    Programming (and testing) work much better if you deal with one thing at a time.

    HIH

    Winston
     
    F is for finger. Can you stick your finger in your nose? Doesn't that feel nice? Now try this tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic