Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Using internationalization with jdbc

  Asked By: Erica    Date: Dec 02    Category: Java    Views: 885
  

Someone here must have solved this problem before. We are having a
legacy code which uses raw sql with jdbc. Changing statement and
using "setString" is not an option.
Something like this:


String originalName = "AAA??AAA"; //some international characters
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO user
(id,name) VALUES ('123','"+originalName+"')");
pstmt.execute();
….
pstmt = conn.prepareStatemnt(SELECT name FROM user WHERE id='123'");
ResultSet rs = pstmt.executeQuery();
rs.next();
String userName = rs.getString(1);

Now username does not match originalName. We are using Oracle 10.0.1,
jdk 1.5. Columns are NVARCHAR2, and defaultNChar= true.
Has anybody being able to solve this?

Share: 

 

5 Answers Found

 
Answer #1    Answered By: Shiv Patel     Answered On: Dec 02

I guess you need to add "&characterEncoding=utf8" to the end of your database URL.

 
Answer #2    Answered By: Marnia Mian     Answered On: Dec 02

why you don't use unicode instead?
you can convert your string  into unicode
for example:
String name  = "\u0652\u0655" ;

 
Answer #3    Answered By: Ayaz Hashmi     Answered On: Dec 02

Isn't that MySql option? I don't think oracle support that flag on connection url.

 
Answer #4    Answered By: Zane Thompson     Answered On: Dec 02

Maybe OraclePreparedStatement class solve this probelm ,

PreparedStatement pstmt = null;
...
((OraclePreparedStatement)pstmt).setFormOfUse(1,OraclePreparedStatement.FORM_NCH\
AR);

pstmt.setString(1,originalName);

 
Answer #5    Answered By: Constance Reid     Answered On: Dec 02

My string  actually comes from Swing JFileChooser or cut and paste to Swing text box, so I would have Java native string "utf16". If you use jdbc  PreparedStaement with setString method call this would get converted to National Character of Oracle for you. Problem is I am trying to make min changes to code  and not have to add a filter for an specific field. How can I convert utf16 to escaped unicode without adding too much overhead?

 
Didn't find what you were looking for? Find more on Using internationalization with jdbc Or get search suggestion and latest updates.