ORACLE乱码问题,用sqlplus连接不会出现乱码。只要用JAVA连接就会有乱码。

xiaoming851 2004-11-22 09:33:21
操作系统是中文的,
源代码
public String getString(String fieldname) {
try {
String value = rs.getString(fieldname);
if (value == null || value.equals("")) return "";
try {
return new String(value.getBytes("ISO-8859-1"));
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
} catch (SQLException e) {
e.printStackTrace();
}
return "err";
}

操作系统是中文,对方数据库是ORACLE8I的,我的数据库驱动是ORACLE9I自带的那个classes.jar
不知道为什么会出现这种问题,郁闷
...全文
161 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoming851 2004-11-22
  • 打赏
  • 举报
回复
to libin_ftsafe:
都式了,还是不行,剧烈郁闷。。。。
liuyi8903 2004-11-22
  • 打赏
  • 举报
回复
这样吧!你在servlet的doPost和doGet方法里面加上
request.setCharacterEncoding("GB2312");
response.setContentType(CONTENT_TYPE);
试试看.

子陌红尘 2004-11-22
  • 打赏
  • 举报
回复
乱码不是数据库的问题,跟classes.jar估计也没关系,跟你的java应用服务器字符集设置有关。

你使用的是什么应用服务器?Tomcat、Resin、Weblogic其他的什么?

如果不清楚怎么设置应用服务器的字符集,用以下的字符集转换方法在Java代码里尝试转换一下:

public static String getString(String str) {
if (iStringConvert != 0) {
try {
sun.io.ByteToCharISO8859_1 tt = new sun.io.ByteToCharISO8859_1();
str = new String(tt.convertAll(str.getBytes()));
return str;
}
catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
return str;
}

public static String getString8859(String str) {
if (iStringConvert != 0) {
try {
String temp_p = str;
byte[] temp_t = temp_p.getBytes("ISO8859_1");
String temp = new String(temp_t);
return temp;
}
catch (Exception e) {
System.out.println(e.toString());
str = "";
}
}

return str;
}

public static String getGBKBy8859(String str) {
if (iStringConvert != 0) {
try {
String temp_p = str;
byte[] temp_t = temp_p.getBytes("ISO8859_1");
String temp = new String(temp_t, "GB2312");
return temp;
}
catch (Exception e) {
System.out.println(e.toString());
str = "";
}
}

return str;
}

public static String get8859ByGBK(String str) {
if (iStringConvert != 0) {
try {
String temp_p = str;
byte[] temp_t = temp_p.getBytes("GB2312");
String temp = new String(temp_t, "ISO8859_1");
return temp;
}
catch (Exception e) {
System.out.println(e.toString());
str = "";
}
}

return str;
}

public static String getGB2312By8859(String str) {
if (iStringConvert != 0) {
try {
String temp_p = str;
byte[] temp_t = temp_p.getBytes("ISO8859_1");
String temp = new String(temp_t, "GB2312");
return temp;
}
catch (Exception e) {
System.out.println(e.toString());
str = "";
}
}
return str;
}

public static String getStringUTF8(String str) {
if (iStringConvert != 0) {
try {
String temp_p = str;
byte[] temp_t = temp_p.getBytes("UTF-8");
String strRet = "";
for (int i = 0; i < temp_p.length(); i++) {
strRet += ("%" + Integer.toHexString(temp_t[i]));
}
return strRet;
}
catch (Exception e) {
System.out.println(e.toString());
str = "";
}
}
return str;
}


17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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