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

    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.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
    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"/>
    i have also done the user.hbm.xml as
    Java Code:
    <class name="com.attainware.maven2example.model.User"
    		<id name="userId" column="USERID">
    			<generator class="native" />
    		<property name="upfile" type="blob" column="USER_FILEBIN"/>
    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();
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    		Transaction tx = session.beginTransaction();;
    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
    Rep Power


    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, 02:50 PM
  4. file upload
    By sundarjothi in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 06-27-2008, 11:52 AM
  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