Home » Developer & Programmer » JDeveloper, Java & XML » Java's answer to NCHAR/ NVARCHAR?
Java's answer to NCHAR/ NVARCHAR? [message #91226] Wed, 05 June 2002 03:47 Go to next message
PD
Messages: 3
Registered: November 1999
Junior Member
I have a Oracle8i database (with UTF-8 as its National Language), and using 8i classes12.zip as the OCI8 JDBC Driver. I got a table called UNICODE_ENTRY, with 2 columns UNICODE_TEXT(NVARCHAR(255)) and ENCODING(VARCHAR2(128)).
I'm trying to enter a chinese String encoded in UTF-8 into the UNICODE_TEXT column using the following code segment

PreparedStatement statement = null;
ResultSet resultSet = null;
try {
sql.append( "INSERT INTO unicode_entry ( unicode_text, encoding ) " );
sql.append( "VALUES( ?, ? )" );
statement = connection.prepareStatement(sql.toString());
java.io.InputStream ins = new java.io.ByteArrayInputStream(text.getBytes(encoding));
java.io.Reader reader = new java.io.BufferedReader(new java.io.InputStreamReader(ins, encoding));
statement.setCharacterStream(1, reader, text.length() );
statement.setString(2, encoding);
statement.executeUpdate();

But this doesnt seem to work, it giving the following error...

java.sql.SQLException: ORA-12704: character set mismatch
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
at oracle.jdbc.oci8.OCIDBAccess.check_error(OCIDBAccess.java:1597)
at oracle.jdbc.oci8.OCIDBAccess.executeFetch(OCIDBAccess.java:1209)
at oracle.jdbc.oci8.OCIDBAccess.parseExecuteFetch(OCIDBAccess.java:1321)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:1446)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1371)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1900)
at oracle.jdbc.driver.OracleStatement.executeUpdate(OracleStatement.java:693)
at UnicodeAccess.writeToOracleDatabase(UnicodeAccess.java:239)
at UnicodeAccess.main(UnicodeAccess.java:43)

I tried using simply statement.setString(1, text); That didnt work either, gave the same error.
Then I tried using Statement instead of PreparedStatement, that didnt work either. Same error!

The probable solution is to use the following lines of code:
statement = connection.prepareStatement(sql.toString());
((OraclePreparedStatement)statement).setFormOfUse(1, OraclePreparedStatement.FORM_NCHAR);
statement.setString(1,text);

But that would work only with a 9i Database and a 9i Driver. I need a solution to the 8i platform...

Can anyone suggest me where I'm going wrong, or how to simply enter a chinese String encoded into UTF-8 to NVARCHR2 column in Oracle8i DB?

Thanks in advance

PD
Re: Java's answer to NCHAR/ NVARCHAR? [message #91496 is a reply to message #91226] Wed, 09 October 2002 05:34 Go to previous messageGo to next message
Bruce Koski
Messages: 3
Registered: October 2002
Junior Member
How did you get this to work? I am stuck on a similar problem. Thanks.
Re: Java's answer to NCHAR/ NVARCHAR? [message #91537 is a reply to message #91496] Thu, 24 October 2002 17:41 Go to previous messageGo to next message
Bruce Koski
Messages: 3
Registered: October 2002
Junior Member
I have encountered the same problem,
and was wondering if you can forward me this message. My email address is ymakleff@hyperion.com
Thanks in advance, Yaron.
This works [message #91538 is a reply to message #91496] Fri, 25 October 2002 08:02 Go to previous message
Bruce Koski
Messages: 3
Registered: October 2002
Junior Member
reparedStatement ps = con.prepareStatement(
"insert into T (F) values(translate(? using nchar_cs)")
ps.setString(1, unicodeVariable)
ps.executeUpdate()
Previous Topic: Passing REF Cursor from Java to PLSQL as IN parameter
Next Topic: Application Error (jrew.exe)
Goto Forum:
  


Current Time: Thu Aug 05 00:23:00 CDT 2021