Reputation: 1
how to read unicode text from java resultset?
Upvotes: 0
Views: 5386
Reputation: 18861
If you are using DataSource (f.e. com.mysql.jdbc.jdbc2.optional.MysqlDataSource
) you can directly set channel encoding to UTF8 like ds.setEncoding("UTF-8")
Upvotes: 1
Reputation: 1499900
Just read the strings. All strings in Java are unicode already. If you're having problems, then:
ResultSet
but displaying it so it looks like you haven't read it properlyI've seen all of these before now. You should use detailed logging (e.g. of the individual characters, in hex) to work out whether you've got the data correctly or not - that will tell you where to look next.
Upvotes: 2
Reputation: 28074
rs.getString() returns a Java String which is Unicode by definition.
If you get mangled characters, you have to configure your database driver to use the right encoding for the connection to the database.
Upvotes: 3