欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
當PreparedStatement中的參數遇到大字符串 - wubaodan - JavaEye技術(shù)網(wǎng)站

今天在JavaEye上看大牛們的博客突然看到一篇文章標題為:"PreparedStatement中setString方法的異常"讓我大喜,以前在項目中遇到這個(gè)問(wèn)題,一直沒(méi)有得到解決今天終于明白了!

以前項目中的代碼如下:

java 代碼
  1. sql = "INSERT INTO taw_attachment (attachmentname, attachmentfilename,"  
  2.           + "attachmentsize,cruser,crtime,info) VALUES (?,?,?,?,?,?)";   
  3. pstmt.setString( 6,info);//info.length() > 2000   
  4. pstmt.executeUpdate();  

而數據庫中對應的表Interface_log.info varchar2(4000);

在方法頭加入如下代碼:

java 代碼
  1. if (info!=null && info.length()>2000){   
  2.       nfo = info.substring(0,2000); //給這個(gè)大文本截肢   
  3. }  

當再次Debug時(shí)還是拋出:Java.sql.SQLException:數據大小超出此類(lèi)型的最大值!

當使用原始的Statement接口后問(wèn)題解決,郁悶?。。?!

今天在文章中看到:

現在通過(guò)Oracle提供的JDBC文檔來(lái)詳細看看問(wèn)題的來(lái)由。
我們都知道Oracle提供了兩種客戶(hù)端訪(fǎng)問(wèn)方式OCI和thin,
在這兩種方式下,字符串轉換的過(guò)程如下:
 
1、JDBC OCI driver:
在JDBC文檔中是這么說(shuō)的:

If the value of NLS_LANG is set to a character set other than US7ASCII or WE8ISO8859P1, then the driver uses UTF8 as the client character set. This happens automatically and does not require any user intervention. OCI then converts the data from the database character set to UTF8. The JDBC OCI driver then passes the UTF8 data to the JDBC Class Library where the UTF8 data is converted to UTF-16. ”
 
2、JDBC thin driver:
JDBC文檔是這樣的:
“If the database character set is neither ASCII (US7ASCII) nor ISO Latin1 (WE8ISO8859P1), then the JDBC thin driver must impose size restrictions for SQL CHAR bind parameters that are more restrictive than normal database size limitations. This is necessary to allow for data expansion during conversion.
The JDBC thin driver checks SQL CHAR bind sizes when a setXXX() method (except for the setCharacterStream() method) is called. If the data size exceeds the size restriction, then the driver returns a SQL exception (SQLException: Data size bigger than max size for this type) from the setXXX() call. This limitation is necessary to avoid the chance of data corruption when conversion of character data occurs and increases the length of the data. This limitation is enforced in the following situations:
(1)Using the JDBC thin driver
(2)Using binds (not defines)
(3)Using SQL CHAR datatypes
(4)Connecting to a database whose character set is neither ASCII (US7ASCII) nor ISO Latin1 (WE8ISO8859P1)
When the database character set is neither US7ASCII nor WE8ISO8859P1, the JDBC thin driver converts Java UTF-16 characters to UTF-8 encoding bytes for SQL CHAR binds. The UTF-8 encoding bytes are then transferred to the database, and the database converts the UTF-8 encoding bytes to the database character set encoding.”
 
原來(lái)是JDBC在轉換過(guò)程中對字符串的長(cháng)度做了限制。這個(gè)限制和數據庫中字段的實(shí)際長(cháng)度沒(méi)有關(guān)系。
所以,setCharacterStream()方法可以逃過(guò)字符轉換限制,也就成為了解決此問(wèn)題的方案之一。
而JDBC對轉換字符長(cháng)度的限制是為了轉換過(guò)程中的數據擴展。
根據實(shí)際測試結果,在ZHS16GBK字符集和thin驅動(dòng)下,2000-4000長(cháng)度的varchar字段都只能插入1333個(gè)字節(約666個(gè)漢 字)。
 
To sum,解決PreparedStatement的setString中字符串長(cháng)度問(wèn)題可以有兩種辦法:
1、使用setCharacterStream()方法;
java 代碼
  1. pstmt.setCharacterStream(index,new InputStreamReader(myString, myString.length());   

2、使用OCI驅動(dòng)連接Oracle數據庫。
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
java連接oracle數據庫的各種方法及java在數據庫中的含義
Oracle 字符集的查看和修改
一個(gè)簡(jiǎn)單的 JDBC 包裝器
兩種CTF中特殊盲注的總結
Postgresql數據庫的一些字符串操作函數
MySQL Structured Query Language
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久