How can I retrieve a record with Chinese characters in Java programming?

289 Views Asked by At

I got a problem for retrieving a record with Chinese characters in Java. Here is my code:

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());
}

When the program executes the SQL statement, it pops the error: "java.sql.SQLException: Cannot map Oracle character to Unicode". If I retrieve a record without Chinese characters, the program works fine. My database is Oracle and the Chinese characters are in the GBK character set. How can I solve this problem?

0

There are 0 best solutions below