我试图从数据库中获取和更新简体中文字符(GB2312),更新部件在WebLogic10.3 windows机器上工作良好,但在WebLogic10.3 Solaris机器上失败(垃圾字符),但是在这两种环境中,获取和显示中文字符都很好
取DAO
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 更新DAO
getSession().createSQLQuery(notesUpdateQuery)
.setParameter(0, new String(base64.decode(notesByte)))
.executeUpdate();注意事项:源txt文件编码: UTF-8
发布于 2013-01-04 13:59:03
是的,看看Update中的这个:
new String(base64.decode(notesByte))这是使用平台默认编码将byte 64解码的字节数组转换为字符串。byte 64解码的字节数组实际上是用GB2312编码的文本,而不是平台默认编码中的文本。
要正确地转换它,您需要在任何地方指定相同的编码:
new String(base64.decode(notesByte), "GB2312")https://stackoverflow.com/questions/14158468
复制相似问题