中文问题:我的数据库中,中文写入没有问题,但中文却不能正常读出。(sqlserver2000) ????????就是这样,是jsp但只在读出数据的时候是这样,我觉得应该是数据库的问题! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果是JSP,你在程序里面加了这条语句吗?<%@page contentType="text/html;charset=gb2312"%> 因为我用jsp写别的中文没有问题,只是从数据库里来的中文数据有问题绝对是数据库的问题,字段类型该设成什么?varchar不行么? varchar应该是对的阿!!有程序吗?我看看 ejb怎么看啊,我就是findByPrimaryKey只后,在get只要是中文的,就是一堆????? public static String unicodeToGB(String strIn) throws Exception { String strOut = null; if(strIn == null || (strIn.trim()).equals("")) return strIn; byte[] b = strIn.getBytes("GBK"); strOut = new String(b,"ISO8859_1"); return strOut; } public static String GBToUnicode(String strIn) throws Exception { String strOut = null; if(strIn == null || (strIn.trim()).equals(""))return strIn; byte[] b = strIn.getBytes("ISO8859_1"); strOut = new String(b,"GBK"); return strOut; }以上是两个常见的转换方法,出现问题时可以试试 这样编译:javac yourfile.java -encoding iso-8859-1 eternalee(看看) 我是用jbuilder如果要那样编译的话,要怎么做???? 再jbuilder中的project properties中可以改变你的编码为iso8859-1;但读出数据时可能还会遇到问题。就需要:public static String unicodeToGB(String strIn) throws Exception { String strOut = null; if(strIn == null || (strIn.trim()).equals("")) return strIn; byte[] b = strIn.getBytes("GBK"); strOut = new String(b,"ISO8859_1"); return strOut; } 还没有解决么?试试这个:str=new String(str.getBytes("ISO-8859-1"),"gb2312"); 前一阵子我也在为这问题迷惑呢。难道这有这样的写函数的解决办法么?难道不能直接设置从数据库出来的字符集就是GBK的了么?虽然它是按照unicode存储的(我的数据库是oracle)迷惑中...... 存数据时用ISO存到数据库,在jsp中加上!<%@page contentType="text/html;charset=iso-8859-1"%><meta http-equiv="Content-Type" content="text/html; charset=gb2312">我今天刚搞定的! 我前阶段也碰到过类似问题解决的方法是把数据库中字段类型为varchar改为nvarchar即可你试试看 sikuan(葫芦) 问题真的解决了,就是你那方法,感激!!!在这里我想大家讨论原因,为什么这样改就可以了??在我不做设置和转换的情况下,写入和读出分别是什么格式?请sikuan(葫芦)稍等,讨论过后立即给分 这个小程序有一小段不太理解,谁能帮我解释一下 各位大侠帮我看看哪错了!!! 在第三个类中创建内部类实例问题 IO 缓冲区问题 在JAVA中实现像GOOGLE网站上对输入文本自动提示补充功能 晕死,照书抄的程序没用??? 新手求解释 哪里可以下载中文的JAVA类参考手册? JBOSS的问题 [高分请教]JAVA多线程间如何通信? 怎样是编好的java application在windows上像windows应用程序一样直接运行 新手问题,看看这是什么错误?很简单的。
绝对是数据库的问题,
字段类型该设成什么?
varchar不行么?
有程序吗?我看看
public static String unicodeToGB(String strIn) throws Exception {
String strOut = null;
if(strIn == null || (strIn.trim()).equals(""))
return strIn;
byte[] b = strIn.getBytes("GBK");
strOut = new String(b,"ISO8859_1");
return strOut;
} public static String GBToUnicode(String strIn) throws Exception {
String strOut = null;
if(strIn == null || (strIn.trim()).equals(""))return strIn;
byte[] b = strIn.getBytes("ISO8859_1");
strOut = new String(b,"GBK");
return strOut;
}以上是两个常见的转换方法,出现问题时可以试试
我是用jbuilder如果要那样编译的话,要怎么做????
但读出数据时可能还会遇到问题。就需要:
public static String unicodeToGB(String strIn) throws Exception {
String strOut = null;
if(strIn == null || (strIn.trim()).equals(""))
return strIn;
byte[] b = strIn.getBytes("GBK");
strOut = new String(b,"ISO8859_1");
return strOut;
}
试试这个:
str=new String(str.getBytes("ISO-8859-1"),"gb2312");
写函数的解决办法么?
难道不能直接设置从数据库出来的字符集就是GBK的了么?
虽然它是按照unicode存储的(我的数据库是oracle)
迷惑中......
在jsp中加上!
<%@page contentType="text/html;charset=iso-8859-1"%>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
我今天刚搞定的!
解决的方法是把数据库中字段类型为varchar改为nvarchar即可
你试试看
在这里我想大家讨论原因,为什么这样改就可以了??
在我不做设置和转换的情况下,写入和读出分别是什么格式?
请sikuan(葫芦)稍等,讨论过后立即给分