ÔÚʹÓÃoracleʱ£¬Èç¹ûÔÚÒ»¸övarchar2(4000)µÄ×Ö¶ÎÉϲåÈëµÄ×Ö·û¹ý³¤£¨Ò»°ãÖ»ÄܲåÈë666¸öºº×Ö£¬ÊÓ×Ö·û¼¯²»Í¬»áÓÐËù²»Í¬£©£¬»áµ¼ÖÂʧ°Ü£¬¾ßÌ屨´í»áÒòÇý¶¯°æ±¾²»Í¬¶ø²»Í¬¡£
ÔÒòÒ»£º
666 ºº×ÖËùÓõıàÂëÀï (¿ÉÄÜÊÇ UTF8) ÿ¸ö×ÖÕ¼ÁË 3 bytes£¬µ±´æµÄʱºò, ûÓÐ×÷ºÃ charset-encoding µÄת»»£¬Ôì³ÉÄãµÄÿ¸ö byte ±»µ±³ÉÊÇ java µÄÒ»¸ö char (2 bytes) À´´æ£¬Õâʱ£¬Ã¿¸öºº×ÖÒªÓà 3x2=6 bytes ´æ½ø oracle ÖУ¬ËùÒÔ×î¶àÖ»ÄÜ´æµ½ 4000/6=666 ×Ö¡£
ÔÒò¶þ£º
ÕâÊǸöOracleJDBCÎÊÌâ¡£Ò»°ãÖ±½ÓÓÃps.setString()ÉèÖÃ×Ö·û´®Êý¾Ýʱ£¬OracleµÄJDBCÇý¶¯»á½«ÖÐÎÄת»»Îª2×Ö½Ú»ò3×Ö½Ú£¬²»¹Ì¶¨µÄ£¬Òò´Ë¾³£»áÔ½½ç¡£Èç¹û¸ÄΪps.setCharacterStream()¾ÍÊǹ̶¨µÄÿ¸öÖÐÎÄÁ½¸ö×Ö½Ú¡£
½â¾ö°ì·¨£º
·½·¨Ò»£º
ʹÓÃps.setCharacterStream()²åÈë¶à¸ö×Ö·û£º
ÔÀ´µÄ´úÂë
//ps.setString(i, ((String) parameter));
String s = (String) parameter;
ps.setCharacterStream(i, new StringReader(s), s.length());
·½·¨¶þ£º
²»ÓÃPreparedStatement£¬¶øÖ±½Ó×é³ÉsqlÓï¾ä²åÈë¡£
·½·¨Èý£º
ÓÃCLOB×Ö¶ÎÀ´½â¾ö¡£