UTF characters Java JDBC

From: Barney <barney.hyll_at_gmail.com>
Date: Thu, 19 Nov 2009 12:43:17 -0800 (PST)
Message-ID: <bb546eeb-99b3-48e9-a8cc-6746174e337b_at_b2g2000yqi.googlegroups.com>



Hi,

I have a Java app that connects to an Oracle DB and I'm having problems when saving data that include some characters that are only available in UTF-8.

The characters in question : € ™ Œ œ ƒ

I tried to add the following argument to the JVM but it did not worked : -Dclient.encoding.override=UTF-8

Question #1 : Is there something I can do on the Java app side ?

Question #2 : Is there something I can do on the Oracle DB side ?

Below the result of the query SELECT * FROM NLS_DATABASE_PARAMETERS on the database, along with the Java code that interacts whit it.

Thank you very much.

  • ------------------------------
  • DB

PARAMETER
VALUE




NLS_LANGUAGE
FRENCH
NLS_TERRITORY
CANADA
NLS_CURRENCY
$

NLS_ISO_CURRENCY
CANADA
NLS_NUMERIC_CHARACTERS .
NLS_CHARACTERSET
WE8ISO8859P1
NLS_CALENDAR
GREGORIAN
NLS_DATE_FORMAT                YYYY/MM/

DD
NLS_DATE_LANGUAGE
FRENCH
NLS_SORT
FRENCH
NLS_TIME_FORMAT
HH24:MI:SSXFF
NLS_TIMESTAMP_FORMAT RR-MM-DD
HH24:MI:SSXFF
NLS_TIME_TZ_FORMAT HH24:MI:SSXFF TZR
NLS_TIMESTAMP_TZ_FORMAT RR-MM-DD HH24:MI:SSXFF TZR
NLS_DUAL_CURRENCY
$

NLS_COMP
BINARY
NLS_LENGTH_SEMANTICS
BYTE
NLS_NCHAR_CONV_EXCP
FALSE
NLS_NCHAR_CHARACTERSET
AL16UTF16
NLS_RDBMS_VERSION
9.2.0.3.0
// ------------------------------

// Java code

package charset;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

public class TestClass {

        private String url;

	public TestClass() {
		// localhost
	    url = "jdbc:oracle:thin:_at_localhost:1521:XE";
	}

	public int executeUpdate() throws Exception {

        Class.forName ("oracle.jdbc.driver.OracleDriver").newInstance
();
		Properties props = new Properties();
		props.put("user", "username");
		props.put("password", "password");

	    Connection connJHA = DriverManager.getConnection(url, props);
        Statement stmt = connJHA.createStatement
(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        String descr = "€ ™ Œ œ ƒ";
        String strUpdate = "UPDATE PARAM SET DESCR='" + descr + "'
WHERE CODE='CODE_1'";
        return stmt.executeUpdate(strUpdate);
	}

	public void executeSelect() throws Exception {

        Class.forName ("oracle.jdbc.driver.OracleDriver").newInstance
();
		Properties props = new Properties();
		props.put("user", "username");
		props.put("password", "password");

	    Connection connJHA = DriverManager.getConnection(url, props);
        Statement stmt = connJHA.createStatement
(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        String strQuery = "SELECT DESCR FROM PARAM WHERE
CODE='CODE_1'";
        ResultSet rs = stmt.executeQuery(strQuery);
        rs.next();
        String descr = rs.getString(1);
        System.out.println("descr = " + descr);
	}

	public static void main(String[] args) {
		TestClass test = new TestClass();
		try {
			if (test.executeUpdate() != 0) {
				test.executeSelect();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

} Received on Thu Nov 19 2009 - 14:43:17 CST

Original text of this message