Re: Japanese Character storing in Oracle using JDBC

From: Swaminathan Balasubramanian <swamib_at_netscape.com>
Date: 1999/02/22
Message-ID: <36D19630.FBB94F52_at_netscape.com>#1/1


Thanks very much for the help.

My problem is that the data of japanese character to be stored in Oracle is a content of a letter sizing 13k+ (sometimes goes upto 20k), which obviously cannot be stored as varchar in Oracle. Thats the reason why we use LONG. While writing from Applet to Oracle as a LONG, i am using setUnicodeStream(). In this case, is it possible to retrieve by changing 'defaultRowPrefetch' to varchar so that the retrieved values does not go garbled..

The char set we use in applet is also SJIS. The Oracle db is set with NLS_LANG paramter has 'AMERICAN_AMERICA.AL24UTFFSS '. Is there any problem with this config.

Once again, Thanks very much,
Swami

Tom Tanaka wrote:

> Swaminathan Balasubramanian wrote in message
> <36CDBC5A.A74BC2F6_at_netscape.com>...
> >Thanks for the help.
> >
> >I use Oracle 7.3.4 and JDBC (type 4) Driver, as the application runs as an
> >applet in a browser and connects to the Oracle database server.
> >
> >Is it possible to save the japanese text content as LONG data type in
 Oracle and
> >retrieve using getUnicodeStream() or getBinaryStream() method of Java and
 then
> >convert them to Unicode string ?. Will these alternative work?
> >If possible, how do we save it as LONG type?
> >
> >Thanks very much,
> >Swami.
>
> No, you cannot save japanese text content as LONG data type. Well, actually
> you can, but the text will definitely
> be garbled when you retrieve them. Alternately, you can change the
> "defaultRowPrefetch" property and set the column from LONG data type to
> VARCHAR data type. Also, the default japanese code for Oracle is in SJIS
> format. So if your applet needs to handle other japanese code such as EUC,
> you can use Oracle SQL command for japanese conversion. Oracle7.3 has a
> japanese text conversion command for SQL;i.e. CONVERT("japanese text",
> 'JA16SJIS', 'JA16EUC').
>
> The following is a sample code for your reference:
> --begin--
> import java.sql.*;
> import java.io.*;
>
> public class SampleDB {
> public static void main(String args[]) {
> try {
> Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
> String url = "jdbc:odbc:Oracle";
> String userID = "john";
> String passwd = "doe";
> Connection con = DriverManager.getConnection(url, userID, passwd);
>
> Statement stmt = con.createStatement();
> String query = "select * from \"japanese data table\"";
> ResultSet rs = stmt.executeQuery(conv2SjisString(query));
>
> ResultSetMetaData rmeta = rs.getMetaData();
> int column = rmeta.getColumnCount();
> System.out.println("Column = " + column);
>
> System.out.println("No.\tColumn Name\tColumn Type Name");
> System.out.println("---\t" + "--------------\t" +"----------------");
>
> for (int i = 1; i <= column; i++) {
> System.out.print(i + "\t" + getUnicodeColumnName(rmeta, i) + "
> \t");
> System.out.println(rmeta.getColumnTypeName(i));
> }
> rs.close();
> stmt.close();
> con.close();
> } catch (SQLException e) {
> try {
> byte mb[] = e.getMessage().getBytes("8859_1");
> System.out.println(new String(mb, "SJIS"));
> } catch (java.io.UnsupportedEncodingException e2) {
  System.out.println(e2.toString());
> }
> } catch (ClassNotFoundException e) {
 System.out.println(e.toString());
> }
> }
> static String conv2SjisString(String str) throws SQLException {
> String ustr = "";
> try {
> ustr = new String(str.getBytes("SJIS"),"8859_1");
> } catch (IOException e){
 System.err.println("IO error: str="+str);
> }

 return ustr;
> }
> static String getUnicodeColumnName(ResultSetMetaData rmeta, int index)
> throws SQLException {
> String ustr = "";
> String s = rmeta.getColumnName(index);
> if(s == null)
> return null;
> try {
> ustr = new String(s.getBytes("8859_1"));
> } catch (IOException e){
 System.err.println("IO error: columnIndex="+index);
> }

 return ustr;
> }
> }
> --- end ---
>
> ----------------------------------------------------------------------------
> ----
>
> )_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)
>
> Tom Tanaka
> President/Technical Artist
> DNA,Inc.
> http://www.dnainc.co.jp
> tomatell_at_xx.dnainc.co.jp
> 100% Pure Java Web Search Robot
> at the following URL:
> http://www.dnainc.co.jp/dnabot/
>
> )_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)_)
Received on Mon Feb 22 1999 - 00:00:00 CET

Original text of this message