Problems caused by changing varchar2 to clob

Source: Internet
Author: User

JDBC preparedstatement. setstring () and resultset. getstring () process clob and string in the same way. Although the type is changed, the program is slightly modified (front-end length verification ).

As the basic data, you need to export the table data of the development database and upgrade it in the official environment using SQL. The clob field cannot be exported normally. If the clob field is less than 4000, you can use to_char to convert and export the data, when the field is greater than 4000, the insert statement execution will have an exception "ORA-01704: String Literal too long ". If there are more than 4000 objects, you can also use a method to insert the first 4000 objects and then update them one by one (set remark = remark + 'xxx '), if the processing volume is large, it will be laborious. Consider the following:

1. Add the varchar2 (4000) column to the database, which is controllable as the basic data length;

2. The set and get methods are added to the bean. The set method performs ultra-long splitting and the get method performs ultra-long stitching;

/** Remarks */private string remark;/** extended remarks */private string remark1;/** concatenates remarks without actual database fields, no actual bean property */Public String getrealremark () {return null = remark? Null: remark + (null = remark1? "": Remark1);}/** sharding remarks */Public void setrealremark (string realremark) throws unsupportedencodingexception {If (null = realremark | realremark. getbytes ("GBK "). length <= 4000) {/* does not exceed 4 kilobytes, And the remark1 column is useless */This. remark = realremark; this. remark1 = NULL;} else if (realremark. getbytes ("GBK "). length <= 7997) {/* exceeds 4 kilobytes, and the remark column contains up to 4 kilobytes of characters */INT Len = 2000; while (true) {If (realremark. substring (0, ++ Len ). getbytes ("GBK "). length> 4000) {// todo: optimized break;} This. remark = realremark. substring (0, len-1); this. remark1 = realremark. substring (LEN-1);} else {} Public String getremark () {return remark;} public void setremark (string remark) {This. remark = remark;} Public String getremark1 () {return remark1;} public void setremark1 (string remark1) {This. remark1 = remark1 ;}


Problems caused by changing varchar2 to clob

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.