i am trying to fetch and update simplified chinese character(GB2312) from database , Update part is works fine in weblogic 10.3 windows machine , but it fails(junk character) in weblogic 10.3 Solaris machine , but Fetching and displaying chines character is working fine in both environments
Fetching 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
Update DAO
getSession().createSQLQuery(notesUpdateQuery)
.setParameter(0, new String(base64.decode(notesByte)))
.executeUpdate();
note: Source txt file encoding : UTF-8
Well yes, look at this in your Update DAO:
new String(base64.decode(notesByte))
That's using the platform default encoding to convert the base64-decoded byte array into a string. The base64-decoded byte array is actually text encoded in GB2312 - not in the platform default encoding.
To convert it properly, you need to specify the same encoding everywhere:
new String(base64.decode(notesByte), "GB2312")