问题描述
- 数据在数据库中查询显示是中文,输出到页面转换为utf-8之后,输出为乱码,求解
-
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">Insert title here
<%
String url = "jdbc:odbc:DSSchool;useunicode=true;characterEncoding=UTF-8";
String sqlstr,no,name;
int age;
Connection con; // 建立连接类
Statement stmt; // 建立SQL语句执行类
ResultSet rs = null;// 建立结果集类
// 告诉程序使用JDBC与ODBC桥建立数据库连接
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(url,"sa","123456");
stmt = con.createStatement();
sqlstr = "select * from T_STUDENT";
rs = stmt.executeQuery(sqlstr);
while (rs.next()){
String stuno = new String (rs.getString("STUNO").getBytes("GBK"),"UTF-8");
String stuname = new String ( rs.getString("STUNAME").getBytes("GBK"),"UTF-8");
out.print(stuno+" "+stuname + " "+"
");
}
stmt.close();
con.close();
%>
解决方案
格式问题和保存在软件的下载位置