这是我的sql查询字符串:
select t.create_date, concat('+', t.points) as points,
case t.obtain_ways
when 'PURCHASE_PRODUCT' then '理财赠送'
when 'SOCIAL_NETWORK_SHARE' then '社交网络分享'
when 'CHECK_IN' then '签到'
when 'RAFFLE' then '抽奖'
end as obtain_ways
from points_record t where [custId] and delete_flag=0
当我使用mysat函数如concat或sum函数而我的sql字符串包含中文字符时,来自ResultSetMetaData的getColumnType值很奇怪。
ResultSetMetaData resultmd = resultSet.getMetaData();
int type = resultmd.getColumnType(2);
// type is -3 VARBINARY
类型为-3,即VARBINARY,但应为12(VARCHAR)。
当我使用英文单词而不是汉字时,每件事情都可以。
select t.create_date, concat('+', t.points) as points,
case t.obtain_ways
when 'PURCHASE_PRODUCT' then 'a'
when 'SOCIAL_NETWORK_SHARE' then 'b'
when 'CHECK_IN' then 'c'
when 'RAFFLE' then 'd'
end as obtain_ways
from points_record t where [custId] and delete_flag=0
列类型:
ResultSetMetaData resultmd = resultSet.getMetaData();
int type = resultmd.getColumnType(2);
// type is 12 VARCHAR
但是当我使用另一个安装了另一个计算机的数据库时,无论我使用中文字还是英文单词,结果都没问题。
我的项目编码是UTF-8,我的数据库编码是:
Variabile_name value
character_set_client utf8
character_set_connection utf8
character_set_database utf8
character_set_filesystem binary
character_set_results utf8
character_set_server utf8
character_set_system utf8
character_sets_dir C:\Program Files\MySQL\MySQL Server 5.0\share\charsets\
和另一个db编码是:
Variabile_name value
character_set_client utf8
character_set_connection utf8
character_set_database utf8
character_set_filesystem binary
character_set_results utf8
character_set_server utf8
character_set_system utf8
character_sets_dir /usr/local/mysql/share/charsets/