mybatis-3
mybatis-3 copied to clipboard
mybatis does not support N' for sql server
i have an statement like below for sql server,
insert into student(name,age) values(N'张三',10)
it seems we can not use N'#{name}' in mapper file.
Hello @sharpboy2008 ,
I don't think N
is necessary in normal situation.
What happens if you just write #{name}
instead of N'#{name}'
?
non-English will become question marks,such as below, one is with N. the other is not. can this be fixed?
That probably means that you set sendStringParametersAsUnicode=false
in the JDBC URL (the default is true).
Removing this option may fix the problem, but it could have negative impact on performance.
Another solution is to specify jdbcType
or typeHandler
explicitly in each parameter reference.
-
#{name,jdbcType=NVARCHAR}
-
#{name,typeHandler=org.apache.ibatis.type.NStringTypeHandler}
It is also possible to override the default type handler for String
in the config, but it may cause error when querying data if the columns are defined as VARCHAR
, not NVARCHAR
.
yes.we can not do this with 'sendStringParametersAsUnicode=false' as you said it huge impact on the performance. i will try either of them, is there any impact? #{name,jdbcType=NVARCHAR} #{name,typeHandler=org.apache.ibatis.type.NStringTypeHandler}
how about nvarchar(max)? we have some columns with nvarchar(max).still #{name,jdbcType=NVARCHAR}
@sharpboy2008 , The size of the column should not matter. If you have any difficulty, please provide a small demo project like these so that we can reproduce the same issue on our end.
我有如下针对 sql server 的语句, insert into student(name,age) values('N'||'张三',10)
我有如下针对 sql server 的语句, insert into student(name,age) values('N'||'张三',10)
I'm learning sql server, I'm not familiar with N sql,but the statement may have an error (in SQL Server 2008R2).
As there is no reply, I assume the problem has been resolved.
That probably means that you set
sendStringParametersAsUnicode=false
in the JDBC URL (the default is true). Removing this option may fix the problem, but it could have negative impact on performance.Another solution is to specify
jdbcType
ortypeHandler
explicitly in each parameter reference.
#{name,jdbcType=NVARCHAR}
#{name,typeHandler=org.apache.ibatis.type.NStringTypeHandler}
It is also possible to override the default type handler for
String
in the config, but it may cause error when querying data if the columns are defined asVARCHAR
, notNVARCHAR
.
Only #{name,typeHandler=org.apache.ibatis.type.NStringTypeHandler}
works.