Home > Database > Mysql Tutorial > Java中连接数据库时汉字都变成问号问题(mysql)_MySQL

Java中连接数据库时汉字都变成问号问题(mysql)_MySQL

WBOY
Release: 2016-06-01 13:11:36
Original
1996 people have browsed it


package Login;import java.sql.Connection;import java.sql.DriverManager;public class GetConn { public Connection conn=null; public Connection getConnection(){ try{ Class.forName("com.mysql.jdbc.Driver"); String url="jdbc:mysql://localhost:3306/select_courses" +"?useUnicode=true&characterEncoding=utf8"; //确定字符集 String user="root"; String passWord=""; conn=DriverManager.getConnection(url,user,passWord); if(conn!=null){ System.out.println("数据库链接成功"); } }catch(Exception e){ e.printStackTrace(); } return conn; }}
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template