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 ();