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