說明:用的Oracle 11g 數據庫 最近在做的一個需求,版權信息要保存到數據庫中,“CopyRight©****公司” 而保存到數據庫就變成了“CopyRight?****公司”,
版權字段類型用的是VARCHAR2、CLOB 都試過了,還是變成問號。於是網上找了一下,解決了這個問題。
1. 把數據庫的字段的類型從CLOB改成NVARCHAR2。
2. 程序保存數據庫時要注意字段前面必須加N‘*******’,如:insert into tb (col) values(N'中文')
先測試一下這個sql 我用的update執行的 是可以得
3、放到代碼中,剛開始,我是在mybatis update語句中直接加了N
set FOOT_COPYRIGHT = N#{footCopyright,jdbcType=NVARCHAR}
測試的時候,就會拋異常,映射異常,異常信息如下:
Caused by: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='settingStatus', mode=IN, javaType=class java.lang.Object, jdbcType=VARCHAR, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #10 with JdbcType VARCHAR . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #10 with JdbcType VARCHAR . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: 無效的列索引
然后把前邊的N去掉試了一下,就可以了,最終
set FOOT_COPYRIGHT = #{footCopyright,jdbcType=NVARCHAR}