Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Chinese character in the csv file

843842Oct 3 2008 — edited Oct 3 2008
Hi all,

I have code below , I am using OpenCSV API to write data to csv.
I am using jdk1.4 and NetBean 6.1 and database is DB2.

The DB2 encoding is UTF-8 , the chinese data is inserted correct to database , but when i tried to retrieve it using
rs.getString("REGISTER_NAME") , it display "???????" , below is the code

FileWrite fileWriter = new FileWriter(PARENT_PATH + WRITE_FILE);
CSVWriter writer = new CSVWriter(fileWriter);

// feed in your array (or convert your data to an array)
while (rsVoucherCode.next()) {
String register_name = rsVoucherCode.getString("REGISTER_NAME");
System.out.println("register_name :" + register_name);
String test = new String(register_name.getBytes("UTF-8"), "Big5");
int register_optin = rsVoucherCode.getInt("REGISTER_OPTIN");
String[] entries = (test+"#"+String.valueOf(register_optin)).split("#");
writer.writeNext(entries);
}
writer.close();

Anyone have any ideas or suggestion is much appreciated . Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 31 2008
Added on Oct 3 2008
3 comments
382 views