各位大虾救急!JSP中如何显示和写入中文到UTF-8的数据库中去啊?

ljm 2003-06-05 02:34:01
我的数据库的字体编码为UTF-8,怎样我才能写入字体编码为UTF-8的中文呢,用普通的Insert语句输入的中文在数据库中为乱码(用UTF-8看是乱码,用简体中文可以看);同理如何显示UTF-8的中文呢?望各位大虾发表高见
谢谢
...全文
31 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
logix 2003-06-09
  • 打赏
  • 举报
回复
mysql有连接参数的,试试下面两个
useUnicode="true"
characterEncoding="gb2312"
ljm 2003-06-05
  • 打赏
  • 举报
回复
非常遗憾,LiGun(中国心_HSK) 的方法也不行。。。。。怎么办????
ljm 2003-06-05
  • 打赏
  • 举报
回复
谢谢各位的热情,
第三位luckyfanjian(luckyfan)方法我试过多遍,不行!
我问一下logix(),我用的是mysql,能告诉我什么函数可以转换吗?谢谢!
我正在试一试LiGun(中国心_HSK) 的方法。
luckyfanjian 2003-06-05
  • 打赏
  • 举报
回复
可以这样写:
public static String charConvert(String strSource){
if (strSource == null){
return "";
}
else{
try{
String str = new String(strSource.getBytes("GB2312"), "UTF-8");
System.out.println(str);
return str;
}
catch (Exception ex){
System.out.println(ex.toString());
return "";
}
}
}
LiGun 2003-06-05
  • 打赏
  • 举报
回复
给你一个转换类

进入数据库数据,都通过者各类转换一下

public class ISOtoGBK {
public static String convert( String str ) {
if (str.trim()=="")
{
return null;
}
try {
byte[] bytesStr=str.getBytes( "ISO-8859-1" ) ;
return new String( bytesStr, "GBK" ) ;
}
catch( Exception ex ) {
return str ;
}
}
}
logix 2003-06-05
  • 打赏
  • 举报
回复
你用的什么数据库,看看它的jdbc连接串里有没有字符集参数,sybase,mysql等都是有的。

81,090

社区成员

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

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