当前位置: 技术问答>java相关
JDBC联接MySQL,不能正常输出中文
来源: 互联网 发布时间:2017-03-30
本文导语: JDBC联接MySQL,不能正常输出中文 ------------------------------------ ------通过JDBC联接MySQL的代码如下 Class.forName( "com.mysql.jdbc.Driver" ); Connection conn = DriverManager.getConnection( "jdbc:mysql://localhost/Yttrium","Yttrium","XXX"); Statement stmt ...
JDBC联接MySQL,不能正常输出中文
------------------------------------
------通过JDBC联接MySQL的代码如下
Class.forName( "com.mysql.jdbc.Driver" );
Connection conn = DriverManager.getConnection( "jdbc:mysql://localhost/Yttrium","Yttrium","XXX");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery( "SELECT '我的名字' AS Name" );
rs.next();
System.out.println( rs.getString( "Name" ));
------但不能正常输出中文“我的名字”,请问如何设置才能正常输出中文?
------------------------------------
------通过JDBC联接MySQL的代码如下
Class.forName( "com.mysql.jdbc.Driver" );
Connection conn = DriverManager.getConnection( "jdbc:mysql://localhost/Yttrium","Yttrium","XXX");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery( "SELECT '我的名字' AS Name" );
rs.next();
System.out.println( rs.getString( "Name" ));
------但不能正常输出中文“我的名字”,请问如何设置才能正常输出中文?
|
"jdbc:mysql://localhost/Yttrium?useUnicode=true&characterEncoding=gb2312"
|
将
删除
|
先确保你插入数据库的是中文而不是一堆???
...
....
String Name = new String ((request.getParameter("Name")).getBytes("ISO8859_1"),"GBK");
..
select Name as '我的名字'
...
....
String Name = new String ((request.getParameter("Name")).getBytes("ISO8859_1"),"GBK");
..
select Name as '我的名字'