How to retrieve UTF-8 data using oci driver
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   rama_subramanian
Posted On:   Friday, December 14, 2001 07:56 AM

hi,
We have Data stored in Oracle-8i which has UTF-8 format enabled.

When we use thin driver we are getting the data in UTF-8 format.But when we use oci driver we don't recieve the UTF-8 value.(this is happening for inserting into the database also).

could anyone help to solve the above.

Thanks in advance.

Re: How to retrieve UTF-8 data using oci driver

Posted By:   Anonymous  
Posted On:   Monday, December 17, 2001 01:17 AM

I'm sure Bernie's answer is correct as he is clearly experienced in Oracle. However, the behavior you describe would seem to be a bug to me and I would report it.


You should always receive data in Unicode and send it out in Unicode in JDBC. The driver and DBMS should handle any conversion to the encoding or character set that was specified in the database. Otherwise you would always have to do things as Bernie describes depending on the character set used in the database and portability is gone. Looks like a bug ( if the behavior is confirmed ) to me. Plus two varieties of the same driver shouldn't conflict.

Re: How to retrieve UTF-8 data using oci driver

Posted By:   Bernie_Acs  
Posted On:   Saturday, December 15, 2001 01:34 PM

The OCI driver uses a OS resident DLL or shared libraries that are installed on the platform during the Oracle Client software install. Some of the dynamics would therefor be dependant on the OS behaviors and environment. One approach to handling the issue with your OCI drivers might be to use the String constructor flavor that allows you to specify the character encoding versus the default encoding:


java.lang.String( byte[] bytes, String enc )


Review String JavaDoc at Class String

IE..

On INPUT




...

PreparedStatement pstmt = conn.prepareStatement(
"insert into table1 ( myKey, myData ) values ( ? , ? )" );
pstmt.setString( 1, theKey );
pstmt.setString( 2, new String( theData, "UTF-8") );

...

On Output




...

String theData = new String ( resultSet.getString( 2 ).getBytes( "UTF-8") );

...
About | Sitemap | Contact