如何使用jdbc和MySQL正确设置utf8编码? [英] How to properly set utf8 encoding with jdbc and MySQL?

查看:970
本文介绍了如何使用jdbc和MySQL正确设置utf8编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JDBC和MySQL在我的项目中可以正常工作,除非涉及到重音字符. 这是我用来访问数据库的URL:

JDBC and MySQL work just fine in my project except when it comes down to accented characters. This is the URL I use to access the database:

jdbc:mysql://localhost:3306/dbname?useUnicode=yes&characterEncoding=UTF-8

假设一个resultSet = preparedStatement.executeQuery(),然后一个System.out.println(resultSet.getString("text_with_accents"));.存储在数据库中的是àèìòù(请注意,我已经在数据库及其所有表中设置了正确的编码),但是得到的是?????.

Suppose a resultSet = preparedStatement.executeQuery(), and then a System.out.println(resultSet.getString("text_with_accents"));. What's stored in the database is àèìòù (note that I've already set the right encoding in the database and all its tables), but what I get is ?????.

有没有办法解决这个问题?

Is there a way to fix this?

推荐答案

尝试更改您的网址,如

url="jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=utf8" 

&必须表示为&

这篇关于如何使用jdbc和MySQL正确设置utf8编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆