2010-08-25 58 views
0

如何,我们可以在MySQL中使用Java和JAVA如何,我们可以在MySQL中使用JAVA

+0

我有同样的问题,我解决它,并在我的博客张贴它看到链接 [Unicode教程](http://uwudamith.wordpress.com/2011/09/02/how-to-insert-unicode -values-to-mysql-using-java /)我认为这会很有用。 – Damith 2011-10-20 08:07:15

回答

1

首先,字符集的MySQL VARCHARshould be UTF-8阅读它添加Unicode文本添加Unicode文本。

ALTER TABLE t MODIFY latin1_varchar_col VARCHAR(M) CHARACTER SET utf8; 

然后,你就应该能够使用Statement.setString() without worry

PreparedStatement updateSales = con.prepareStatement("UPDATE COFFEES SET SALES = ? WHERE COF_NAME LIKE ? "); 
updateSales.setInt(1, 75); 
updateSales.setString(2, "Colombian"); 
updateSales.executeUpdate(): 

事情要小心:

  • 如果从文件中读取文本,请确保您读取右侧字符集中的文件。请参阅InputStreamReader的构造函数。
  • 如果数据库中的列不是UTF-8格式,请小心!

这就是我现在所能想到的。

相关问题