jsp显示数据库内信息出现乱码,求大神解决啊
jsp页面<%inttotalRecords=0;ResultSetrs=null;UserDaoud=newUserDao();rs=ud.selUser();if(r...
jsp页面
<%
int totalRecords = 0;
ResultSet rs = null;
UserDao ud=new UserDao();
rs = ud.selUser();
if(rs!=null)
{
%>
<table width="500" border="1">
<caption>通讯信息</caption>
<tr>
<th>姓名</th>
<th>所在部门</th>
<th>联系电话</th>
</tr>
<% while(rs.next())
{
totalRecords++;
%>
<tr align="center" valign="middle">
<td>
<%=rs.getString("name")%>
</td>
<td><%=rs.getString("sector")%></td>
<td><%=rs.getString("phone")%></td>
</tr>
<%}%>
</table>
<p>共<%=totalRecords%>个用户
<%}%>
JAVABEAN封装页面
public ResultSet selUser(){ //查询
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:data","","");
String sql="SELECT * from userlist order by id desc";
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();
}catch(Exception e){
e.printStackTrace();
}
return rs;
}
显示界面。。数据库里是中文的 展开
<%
int totalRecords = 0;
ResultSet rs = null;
UserDao ud=new UserDao();
rs = ud.selUser();
if(rs!=null)
{
%>
<table width="500" border="1">
<caption>通讯信息</caption>
<tr>
<th>姓名</th>
<th>所在部门</th>
<th>联系电话</th>
</tr>
<% while(rs.next())
{
totalRecords++;
%>
<tr align="center" valign="middle">
<td>
<%=rs.getString("name")%>
</td>
<td><%=rs.getString("sector")%></td>
<td><%=rs.getString("phone")%></td>
</tr>
<%}%>
</table>
<p>共<%=totalRecords%>个用户
<%}%>
JAVABEAN封装页面
public ResultSet selUser(){ //查询
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:data","","");
String sql="SELECT * from userlist order by id desc";
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();
}catch(Exception e){
e.printStackTrace();
}
return rs;
}
显示界面。。数据库里是中文的 展开
7个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询