-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: saving image file to mysql
PostPosted: Sat Nov 25, 2006 7:02 am 
Newbie

Joined: Sat Nov 25, 2006 6:57 am
Posts: 12
Location: india
I need to save image file in MySQL database, how can i achieve this using hibernate?

Thanks,
Naresh


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 27, 2006 3:55 am 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
make a blob column, and map a byte[] or File to it. You should be able to search for examples of doing this, and it is not always trivial... :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 27, 2006 7:29 am 
Regular
Regular

Joined: Sat May 20, 2006 3:49 am
Posts: 78
I made it with a ByteArrayOutputStream:

Code:
            FileInputStream in = new FileInputStream(file);
            ByteArrayOutputStream out = new ByteArrayOutputStream();

            byte[] b = new byte[1024];
            while (in.read(b)!=-1 ) {
                out.write(b);
            }

            return out.toByteArray();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.