Results 1 to 2 of 2
  1. #1
    liljejalil is offline Member
    Join Date
    Jan 2009
    Posts
    1
    Rep Power
    0

    Default File upload into database using Hibernate

    Hello all,

    Can anyone please help..

    I am designing a webapplication in java. I have set up forms and sucessfully upload data into mysql database. I now want to upload a file.

    i have created my class..

    Java Code:
    import java.io.Serializable;
    import java.sql.Blob;
    
    public class User implements Serializable {
    
        private Long userId;
      
        private Blob upfile;
    
    	public Long getUserId() {
    		return userId;
    	}
    
    	public void setUserId(Long userId) {
    		this.userId = userId;
    	}
    
    	public Blob getUpfile() {
    		return upfile;
    	}
    
    	public void setUpfile(Blob upfile) {
    		this.upfile = upfile;
    	}
    
       
    }
    and my jsp.page
    Java Code:
    <form name="upform" enctype="multipart/form-data" action="servlet/building?action=UpLoadFile" method="POST">
            Name:<input type="file"/><br>
            <input type="submit" value="Upload"/>
        </form>
    i have also done the user.hbm.xml as
    Java Code:
    <class name="com.attainware.maven2example.model.User"
    		table="users">
    
    		<id name="userId" column="USERID">
    			<generator class="native" />
    		</id>
    
    		
    		<property name="upfile" type="blob" column="USER_FILEBIN"/>
    	</class>
    The problem i have is i dont know what my action class would be like..
    for normal upload i ise somethin like...

    Java Code:
    public void processRequest(HttpServletRequest request,
    			HttpServletResponse response) throws ServletException, IOException {
    		String id = (String) request.getParameter("id");
    user = new User();
    user.setId(id);
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    		Transaction tx = session.beginTransaction();
    		session.save(user);
    		tx.commit();
    the question is how do i do this action for a file. so it stores it in the database.

    Thank you for your help in advance..

  2. #2
    Join Date
    Aug 2008
    Posts
    2
    Rep Power
    0

    Default

    even i was looking for same kind of solution....please help!!

Similar Threads

  1. Upload excel data to access database
    By ravikumar.achi in forum New To Java
    Replies: 20
    Last Post: 01-19-2012, 12:30 PM
  2. Hibernate with multiple database
    By Marty in forum JDBC
    Replies: 3
    Last Post: 12-23-2008, 01:57 PM
  3. how to upload a file?
    By tommy in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 06-30-2008, 03:50 PM
  4. file upload
    By sundarjothi in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 06-27-2008, 12:52 PM
  5. File Upload
    By ShoeNinja in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 11-09-2007, 11:09 PM

Posting Permissions

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