[英]Oracle Varchar2(byte) vs java bytes
I have a table having column defined varchar2(255 byte), When I have insert record via Spring JDBC class I have an error 我有一个表,该表的列定义为varchar2(255字节),当我通过Spring JDBC类插入记录时,出现错误
; nested exception is java.sql.BatchUpdateException: ORA-12899: deer "DBB"."USERS"."NICK" s³tunu iin ok b³y³k (as²l: 441, maksimum: 255)
I have been cropping the String via following method but it does not work 我一直通过以下方法裁剪字符串,但它不起作用
public static String filterStringForTxnLog(String string) {
try {
String noPipe = string.replace('|', '.');
byte noPipeBytes[]= noPipe.getBytes("UTF-8");
if (noPipeBytes.length > 255) {
byte [] cropBytes = new byte[255];
for(int i=0;i<255;i++){
cropBytes[i]=noPipeBytes[i];
}
return new String(cropBytes);
}
return noPipe;
} catch (Exception e) {
logger.error("Nick filter error string:" + string, e);
return "";
}
}
When I have pass the following String size of new String does not fit DB column. 当我通过以下新字符串的字符串大小不适合数据库列。
||123123123123123123123123kşlkşlkşlk12şl3l1k3şl21kşl3üğüğoşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşş123123123123123123123123123123123123123123112321323123123123
This is an encoding issue. 这是一个编码问题。 You have some special UTF-8 characters which are encoded in multiple bytes which is making it more than 255 bytes. 您有一些特殊的UTF-8字符,它们以多个字节编码,因此超过了255个字节。 Hacking it down to 255 bytes is dangerous and could lead to corruption. 将其破解为255个字节很危险,并且可能导致损坏。 You need to account for the encoding. 您需要考虑编码。
您需要将列的定义更改为VARCHAR2(255 CHAR )。
我将字符串创建更改为以下内容,然后可以正常工作。
return new String(cropBytes,"UTF-8");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.