1

I'm trying to retrieve result from MS SQL Server using netbeans.

the problem is when I retrieve Arabic words from the database I receive it as ????? .

Any one can help ?

and here is the code:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection conn = DriverManager.getConnection("jdbc:odbc:yasser");
        System.out.println("test");
        Statement sta = conn.createStatement();
        String Sql = "select * from mainn order by id";
        ResultSet rs = sta.executeQuery(Sql);
                String res = null;
        while (rs.next()) {
                    res = rs.getString("text");
            System.out.println(res);
        }
4

2 回答 2

1

数据库中的数据未正确插入。在将阿拉伯语数据插入数据库时​​,您应该选择 UT-8。并将数据库的字符集更改为 AL32UTF8。

于 2014-01-06T00:09:59.203 回答
1
  • 经过大量搜索后,我发现了一个非常好的解决方法,即将阿拉伯语的列转换为 varbinary,然后将其作为字节放入您的 java 项目中,然后创建一个新字符串,该字符串将字节数组作为构造函数参数,这将使用阿拉伯编码“Windows-1256”来映射阿拉伯字符的正确值

    • 这是代码示例

SQL 选择语句:

select cast([column_name] as varbinary(max)) from [table_name] where [condition]

爪哇代码:

            Statement stat = con.createStatement();
            ResultSet rs = stat.executeQuery("select cast([column_name] as varbinary(max)) from [table_name] where [condition]");
            while (rs.next()) {
                byte[] tmp = rs.getBytes("column_name");
                String cloumn_value = new String(tmp, "Windows-1256");
                //cloumn_value arabic value
            }
于 2015-02-08T17:20:09.173 回答