我正试图从数据库中获取和更新简体中文字符(GB2312),更新部分在weblogic 10.3 windows机器中工作正常,但在weblogic 10.3 Solaris机器中失败(垃圾字符),但获取和显示中文字符在两个环境中都工作正常
<<p> 取刀/strong> while (rs.next()) {
Base64 base64 = new Base64();
byte[] notesByte = base64.encode(rs
.getBytes("notes"));
}
UI (Android)
byte[] notes= Base64.decode(notesByteStr , Base64.DEFAULT);
notesText.setText(new String(notes, "GB2312")); // Displaying chines char
notesByte= Base64.encode(notesText.getText().toString().trim().getBytes("GB2312"), Base64.DEFAULT) // send to db
<<p> 更新刀/strong> getSession().createSQLQuery(notesUpdateQuery)
.setParameter(0, new String(base64.decode(notesByte)))
.executeUpdate();
注释:源txt文件编码:UTF-8
是的,看看你的Update DAO:
new String(base64.decode(notesByte))
使用平台默认编码将base64解码的字节数组转换为字符串。base64解码的字节数组实际上是用GB2312 - 编码的文本,而不是平台默认编码中的。
要正确转换它,需要在所有地方指定相同的编码:
new String(base64.decode(notesByte), "GB2312")