Using hibernate to store images or binary data in sqlserver

Source: Internet
Author: User

A piece of code written to a friend two days ago is hereby summarized here. The following code can be used for databases other than oracle. The operating method of Oracle is described in roobin, the webmaster of hibernate.org.

First, create an object class. The binary field is of the Java. SQL. Blob type.
Private java. SQL. Blob image;

Notes for XDoclet:
@ Hibernate. Property
Column = "image"

The next step is to save the code of the file. below is only the pseudo code, which is also very simple.
String fname = "C: // javalogo.gif"; // file to be imported
File F = new file (fname );
Fin = new fileinputstream (f );

Object class to be saved jtdsblob = new object class to be saved ();
Jtdsblob. settitle ("test1 ");
Jtdsblob. setimage (hibernate. createblob (FIN ));

/*
* The code for saving objects can be changed to your own method. For more information about paradisesdk, visit
* Http://paradisesdk.dev.java.net
*/
Iparadisedao Dao = daofactory. getinstance ();
Dao. Save (jtdsblob );
Dao.exe cute ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.