我在Java中检索带有中文字符的记录时遇到了问题。这是我的代码:
EntityManagerFactory emfactory = Persistence.createEntityManagerFactory( "Eclipselink_JPA" );
EntityManager entitymanager = emfactory.createEntityManager();
Query query = entitymanager.createQuery("Select e from Employee e where e.id = " + empId);
Employee employee = query.getSingleResult();
if (employee != null)
{
System.out.println(employee.getChineseName());
System.out.println(employee.getChineseAddress());
}
当程序执行SQL语句时,会弹出错误:“java.sql.SQLException:无法将Oracle字符映射到Unicode”。如果我检索没有中文字符的记录,程序运行正常。我的数据库是Oracle,中文字符在GBK character set。我该如何解决这个问题?