使用JAVA将希伯来语写入mySql [英] Writing hebrew to mySql using JAVA

查看:63
本文介绍了使用JAVA将希伯来语写入mySql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的Java方法,可将短消息插入到MySQL数据库中. 该表的默认排序规则为utf8_unicode_ci,而Java代码为:

I have a small Java method that inserts short messages to a MySQL Database. the table's default Collation is utf8_unicode_ci and the java code is:

private void insertMessageToDataBase(String lRoom, String lChatusername,
            String lMessage) {
        try {
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost/embeddedChat?" +
                "user=site_access&password=XXXXXXX");
            addMessageToDataBase = con.prepareStatement("INSERT INTO `" + lRoom + "` (username, message, action)" +
                    " VALUES (?,?,'message');");
            addMessageToDataBase.setString(1, lChatusername);
            addMessageToDataBase.setString(2, lMessage);
            addMessageToDataBase.executeUpdate();
        }
        catch (SQLException e) {
            e.printStackTrace();
        }
    }

问题在于,当lMessage是希伯来语时,结果是字符串'??????'

the problem is that when lMessage is in hebrew the result is a string of '??????'

顺便说一句: 我不知道它是否有帮助,但是还有一个PHP脚本有时会写入此数据库中的另一个相似表,并且工作正常.

BTW: I don't know if it helps but there is also a PHP script that sometimes write to another similar table in this database and it works fine.

推荐答案

在代码中设置UTF-8.看到这个;

Set UTF-8 in your code. See this;

    Connection con = DriverManager.getConnection("jdbc:mysql://localhost/embeddedChat?useUnicode=true&characterEncoding=utf8");

这篇关于使用JAVA将希伯来语写入mySql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆