Java中解决Mysql中文问题的方法总结

通过以下几个步骤(必需):
1 修改my.ini,在[mysqld]和[client]中加入
default-character-set=utf8

2 创建数据库和表时设置default charset:
   CREATE DATABASE IF NOT EXISTS my_db default charset utf8 COLLATE utf8_general_ci;
   create table my_table (name varchar(20) not null default '')type=myisam default charset utf8;

3 设置连接参数
php:
 
mysql_query("set names utf8;");

JDBC
 
  jdbc:mysql://localhost/db?user=user&password=123456&useUnicode=true&characterEncoding=UTF-8
  


4 设置filter(可选)
  	public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest) req;
		request.setCharacterEncoding("UTF-8");
		chain.doFilter(req, res);

	}

你可能感兴趣的:(java,sql,PHP,mysql,jdbc)