简体   繁体   中英

How we can add unicode Text in MySQL using JAVA

我们如何使用JAVA在MySQL中添加Unicode文本并使用JAVA读取它

First, the character set of your MySQL VARCHAR column should be UTF-8 .

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

Then, you should just be able to use 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():

Things to be careful of:

  • If you are reading text from a file, make sure you are reading the file in the right character set. See the constructor of InputStreamReader .
  • Be careful if you have columns in the database that are not in UTF-8 format!

That's all I can think of at the moment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM