In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how Hibernate reads Clob. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Although Hibernate has adapted to a variety of databases, so that the foreground can not feel the database type in the background, different databases have different implementation methods in the two types of access: Blob and Clob. There is really no way for Hibernate in this respect. Fortunately, it is relatively simple to implement in mssql, but what I want to say now is the super troublesome Oracle. The database I am doing is Oracle. There is no doubt that Oracle is indeed a database, but some places are too complex.
Using Hibernate to read Clob and Blob is the same as usual, mainly for saving.
The specific process is as follows:
1. Create a Blob with only one byte
2. Use the flush method to strongly Hibernate the Blob with only one byte
3. A cursor is obtained by saving.
4. Use this cursor to save the real data and implement update operations on the database
The specific implementation code is as follows:
TUser user = new TUser (); user.setImage (Hibernate.createBlob (new byte [1])); Transaction ex = session.beginTransaction (); session.save (user); / / forcibly save this blob session.flush (); / / get the blob cursor session.refresh (user,LockMode.UPGRADE) by refreshing user; / / write the actual content oracle.sql.BLOB blob = (oracle.sql.BLOB) user.getImge (); OutputStream out = blob.getBinaryOutputStream () FileInputStream img = new FileInputStream ("c:\ aaa.jpg"); byte [] buf = new byte [10240]; int len; while ((len = img.read (buf)) > 0). {out.write (buf,0,len);} img.close (); out.close (); tx.commit ()
It's the same for Hibernate to read Clob, except that it creates a blank String: user.setResume (Hibernate.createClob (")).
Thank you for reading! This is the end of this article on "how to read Clob from Hibernate". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.