We have data stored in oracle 10g db which contains french character set. The requirement is to read the data and generate a output file using Java.
I checked the validity of the data in Oracle db via SQL*plus and it looks good.
From windows:
set NLS_LANG=AMERICAN.AL32UTF8
sqlplus scott/tiger
sql> select billing_address from MYTABLE t where ADDRESS_ID=1 ;
billing_address
-----------------------
MONTRÉAL QUÉ
Now when I read the table from Java to generate a output file, the character is all garbled and I see question marks in place of É.
Is there any special encoding that I need to set when I try to read/write the data in Java.
Am using the ojdbc14.jar
and setting the encoding as UTF-8.
Update: Here's my java code snippet.
Charset cs1 = Charset.forName("UTF-8");
PreparedStatement pStmt = conn.prepareStatement("select * from talbe where address_id=1");
ResultSet rs = pStmt.executeQuery();
Writer w = null;
FileOutputStream fos = null;
if(rs.next()) {
String billingaddress = rs.getString("BILLING_ADDRESS");
fos = new FileOutputStream(new File("myout.dat"));
w = new BufferedWriter(new OutputStreamWriter(fos,cs1));
w.write(billingaddress);
}