2012-12-21 55 views
2

我试图插入到我的表希伯来值,但结果总是“??????”。 我应该使用哪种排序规则?我尝试使用hebrew_bin和hebrew_general_ci,结果相同。 我使用Java标签的原因是我的代码是用java编写的,据我所知,在web开发中,你也必须在web脚本中指定排序规则。 所以也许我必须在java代码中做到这一点?正确设置mysql排序规则

编辑 下面是代码:

private String url = "jdbc:mysql://ip:port/"; 
private String dbName = "dbname"; 
private String driver = "com.mysql.jdbc.Driver"; 
private String userName = "user"; 
private String password = "password"; 

....

stmt = conn.prepareStatement("INSERT INTO locations(location) VALUES (?)"); 
        stmt.setString(1, "hebrew sentence"); 
        stmt.execute(); 

现在我该如何更改我的代码为您显示的例子吗?

+0

的数据库您使用的? – Mari

+0

我使用的是mysql db –

+0

哪个charset是数据库使用的? –

回答

-2
set the table you needed to utf8 and all the rows in it to 
utf8 the added this to the connection script:mysql_query("SET NAMES 'utf8'"); 

这将帮助你,我猜

+0

如何才能我这样做:mysql_query(“SET NAMES'utf8'”);在java中? –

+0

mysql_query(“SET NAMES'hebrew'”);尝试在查询之前添加此项并运行.. – Mari

+0

'mysql_query'已弃用,请使用'mysqli'或'PDO' – Cynical

2

由于每一个可能的duplicate你可以试试这个:


发布者:Sai Ye Yan Naing Aye

设置UTF-8在你的代码。请参阅以下内容:

Connection con = DriverManager.getConnection("jdbc:mysql://localhost/embeddedChat?" + 
      "user=site_access&password=XXXXXXXX&useUnicode=true&characterEncoding=UTF-8"); 

个性化你的课程

的连接方法请参阅以下内容:

Connecting to MySQL Using the JDBC DriverManager Interface

JDBC Basics - Establishing a Connection

+0

@ImriPersiado修正,显示用户名和密码的实现。 – jnthnjns

+0

这很混乱,我需要发送3个参数..我只看到1. url,用户名,密码 –

+0

???请详细说明?在我上面的答案中,我有'getConnection(url,用户名,密码,unicode布尔,字符编码)'。告诉我你需要发送什么。 – jnthnjns