qq_20083767
倔强的娃娃笑
采纳率37.5%
2015-10-11 04:25 阅读 3.0k

数据在数据库中查询显示是中文,输出到页面转换为utf-8之后,输出为乱码,求解

3

<%@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();
%>

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • qq_31927819 qq_31927819 2015-10-11 12:34

    格式问题和保存在软件的下载位置

    点赞 评论 复制链接分享

相关推荐