谢谢乔恩·斯基特!
是的。我犯了一个错误,在声明时没有对字符串进行编码。
我的问题是获取存储在 DB2 中的数据,将其转换为日文并提供在网页中进行编辑。我从结果集中得到 dbRemarks。我在帖子中错过了另一件事:
插入时,我正在转换为如下文本:
String text = (String) textConverter.toObject(b);
PreparedStatement prepareStatementUpdate = connection.prepareStatement(updateSql);
prepareStatementUpdate.setString(1, text);
int count = prepareStatementUpdate.executeUpdate();
我可以使用以下代码清楚地检索和显示:
String selectSQL = "SELECT remarks FROM empTable WHERE emp_id = ? AND dep_id=? AND join_date='2013-11-15' ";
prepareStatement = connection.prepareStatement(selectSQL);
prepareStatement.setInt(1, 1);
prepareStatement.setString(2, 1);
ResultSet resultSet = prepareStatement.executeQuery();
while ( resultSet.next() ) {
byte[] bytedata = resultSet.getBytes( "remarks" );
AS400Text textConverter2 = new AS400Text(bytedata.length, 5035,sys);
String javaText = (String) textConverter2.toObject(bytedata);
System.out.println("Remarks after conversion to AS400Text :"+javaText);
}
它适用于 JDBC,但对于使用 JPA,我需要转换为字符串以在网页中进行编辑或存储在表中。所以,我尝试过这种方式,但无法成功:
String remarks = resultSet.getString( "remarks" );
byte[] bytedata = remarks.getBytes();
AS400Text textConverter2 = new AS400Text(bytedata.length, 5035,sys);
String javaText = (String) textConverter2.toObject(bytedata);
System.out.println("Remarks after conversion to AS400Text :"+javaText);