2012-01-30 39 views
0
Connection con = null; 
String url = "jdbc:oracle:thin:@//localhost:1521/xe"; 
String driver = "oracle.jdbc.OracleDriver"; 
String s = "สวัสดี"; 
System.out.println("Thai hello :" + s); 
String temp = s.getBytes() + ""; 
String temp2 = new String(s.getBytes()); 
System.out.println("Thai temp bytes :" + temp); 
System.out.println("Thai temp2 bytes :" + temp2); 
try { 
    Class.forName(driver); 
    con = DriverManager.getConnection(url, "system", "xxxxx"); 

    try { 
     PreparedStatement st = con.prepareStatement("INSERT into encodeleo VALUES(?)"); 
     st.setBytes(1, s.getBytes()); 
     st.executeUpdate(); 
     String temp1; 
     ResultSet rs = st.executeQuery("select name from encodeleo"); 
     rs.next(); 
     temp1 = new String(rs.getBytes("name")); 
     System.out.println("temp1 :" + temp1); 
     System.out.println("1 row affected"); 
    } catch (SQLException se) { 
     se.printStackTrace(); 
     System.out.println("SQL statement is not executed!"); 
    } 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

我試過使用UTF-8,但我無法編碼和解碼Java中的其他語言。如何使用Java字節在Oracle中插入泰語?

請給我一些關於如何使用UTF-8對 字符串進行編碼的想法,插入Oracle並重新獲得它?

回答

0

Oracle DB有能力在其表格中存儲多種語言。我們必須爲此選擇正確的字符集。

你可能面臨的問題,是由於:

  1. 客戶端,輸入數據誰沒有正確配置的NLS配置。
  2. 未正確配置檢索數據的客戶端的NLS配置。在泰語字符集

一個泰語字符需要UTF8或AL32UTF8 3個字節。

和這個Question將幫助你。

NLS_LANG=THAI_THAILAND.TH8TISASCII; 

更多信息Oracle Supported LocalesInternationalization in Java

+0

這是非常有用的感謝阿扎德!!!!!!!! – 2012-01-31 04:34:37

相關問題