Hey Friends
How we can add unicode Text in MySQL using JAVA and reading it using JAVA
views:
18answers:
1
+1
A:
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 Alchemist
2010-08-25 14:14:51