[英]Reading Unicode Text from Java ResultSet
如何从Java结果集中读取Unicode文本?
rs.getString() returns a Java String which is Unicode by definition. rs.getString()返回定义为Unicode的Java字符串。
If you get mangled characters, you have to configure your database driver to use the right encoding for the connection to the database. 如果收到乱码,则必须配置数据库驱动程序以使用正确的编码来连接数据库。
Just read the strings. 只是读字符串。 All strings in Java are unicode already. Java中的所有字符串已经是unicode了。 If you're having problems, then: 如果您遇到问题,请:
ResultSet
but displaying it so it looks like you haven't read it properly 这可能是一个诊断问题-您可能正在从ResultSet
读取正确的数据,但显示了它,因此看起来好像您没有正确读取它 I've seen all of these before now. 我以前看过所有这些。 You should use detailed logging (eg 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. 您应该使用详细的日志记录(例如,以十六进制表示的各个字符)来确定您是否正确获取了数据-这将告诉您接下来要查找的位置。
如果使用的是DataSource(fe com.mysql.jdbc.jdbc2.optional.MysqlDataSource
),则可以将通道编码直接设置为UTF8,例如ds.setEncoding("UTF-8")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.