Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Apr 29, 2002

Insert Multi-Lingual Characters in JDBC


This method allows you to insert multi-lingual characters into an Oracle database. In this tip, the column type is varchar2. The multi-lingual string is converted to its unicode value and a special character is inserted between the characters. The following code demonstrates:
 
import java.sql.*;
import java.util.*;
public class MultiLang
{
 String value="";
 Connection con;
 Statement sat;

 public MultiLang()
 {
   try
     {
       Class.forName("oracle.jdbc.driver.OracleDriver");

con=DriverManager.getConnection
("jdbc:oracle:thin:@ip:port:servername","ui
d","pass");
       sat=con.createStatement();
       String s="some multi-lingual string";
       for(int i=0;i<s.length();i++)
         {
            char c=s.charAt(i);
            int temp=(int)c;
            value += new Integer(temp).toString()+"~";
         }
         sat.executeUpdate("insert into multi
values('"+value+"')");//table name is multi

  // to read the multi-Lingual String from the database
      sat=con.createStatement();
      ResultSet rs=sat.executeQuery("select mulchar from
multi");//column name is mulchar which is varchar2
      rs.next();
      String s1=rs.getString(1);
      String retvalue="";
      StringTokenizer st=new StringTokenizer(s1,"~");
         while(st.hasMoreTokens())
           {
              String temp = st.nextToken();
              char c=(char)(new Integer(temp).intValue());
              retvalue+=new Character(c).toString();
           }
     }
     catch(Exception e)
     {
        System.out.println(e);
     }
   }//end of constructor
}//end of class
Gajendran G
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date