Re: Japanese Character storing in Oracle using JDBC

From: Tom Tanaka <tomatell_at_xx.dnainc.co.jp>
Date: 1999/02/20
Message-ID: <7am3dt$qo3$1_at_nn-tk002.ocn.ad.jp>#1/1


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 Sat Feb 20 1999 - 00:00:00 CET

Original text of this message