如何使用Java字节在Oracle中插入泰语?

时间:2012-01-30 17:49:26

标签: java oracle

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编码和解码其他语言。

请告诉我一些关于如何使用UTF-8编码的想法 字符串,插入Oracle并将其取回?

1 个答案:

答案 0 :(得分:0)

Oracle DB能够在其表中存储多语言。我们必须为此选择正确的字符集。

由于以下原因,您可能会遇到问题:

  
      
  1. 未正确配置输入数据的客户端的NLS配置。
  2.   
  3. 未正确配置检索数据的客户端的NLS配置。
  4.   

泰语字符集中的一个泰语字符需要UTF8或AL32UTF8中的3个字节。

Question会对您有所帮助。

NLS_LANG=THAI_THAILAND.TH8TISASCII;

更多信息Oracle Supported LocalesInternationalization in Java

相关问题