TOMCAT+MYSQL做连接池时的中文件问题如何解决?

zhaoxuefeng 2003-06-30 06:27:40
数据库是MYSQL
当用TOMCAT做连接池时,插入一个中文值到数据库里是乱码
但是在server.xml设置如下:

<parameter>
<name>url</name>
<value>jdbc:mysql://localhost/feaket?username=root;password=sa;useUnicode=true;characterEncoding=GB2312</value>
</parameter>


...全文
41 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhaoxuefeng 2003-07-01
  • 打赏
  • 举报
回复
谢谢你的回复

还是不行,我决的是连接池问题,不知道useUnicode=true;characterEncoding=GB2312在下面的参数中这样用对不对
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost/feaket?username=root;password=sa;useUnicode=true;characterEncoding=GB2312</value>
</parameter>
www203 2003-07-01
  • 打赏
  • 举报
回复
你试试转化或者不转换
还有转换成其他的码

因为可能你的mysql不支持gb2312
那你就试试utf-8
www203 2003-07-01
  • 打赏
  • 举报
回复
你试试转化或者不转换
还有转换成其他的码

因为可能你的mysql不支持gb2312
那你就试试utf-8
unsalted 2003-07-01
  • 打赏
  • 举报
回复
<%!
public String getStr(String str) {
try {
String temp_p = str;
byte[] temp_t = temp_p.getBytes("ISO8859-1");
String temp = new String(temp_t);
return temp;
} catch(Exception e) {
}
return null;
}
%>
zhaoxuefeng 2003-07-01
  • 打赏
  • 举报
回复
我用下面的方法转换后存还是乱码
<%!
public String toChinese(String strvalue){
try{
if(strvalue==null)
return null;
else{
strvalue=new String(strvalue.getBytes("ISO8859_1"),"GBK");
return strvalue;
}
}catch(Exception e){
return null;
}
}

%>
还有什么别的方法吗?我想是不是连接池没有配好
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost/feaket?username=root;password=sa;useUnicode=true;characterEncoding=GB2312</value>
</parameter>
unsalted 2003-07-01
  • 打赏
  • 举报
回复
转换后再存。
zhaoxuefeng 2003-07-01
  • 打赏
  • 举报
回复
没有人知道吗?
自己UP一下
zhaoxuefeng 2003-07-01
  • 打赏
  • 举报
回复
UP

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧