日期:2014-05-20  浏览次数:20626 次

还是数据库乱码问题!搞不明白!
<%@page   contentType= "text/html;charset=gb2312 "%>
<%@page   import= "java.sql.* "%>
<%@page   import= "java.util.* "%>
<%request.setCharacterEncoding( "gb2312 ");%>
<div   align= "center ">
<table   border= "1 "   width= "100% "   id= "table1 ">
<tr>
<td>
<p   align= "center "> 学号 </td>
<td>
<p   align= "center "> 姓名 </td>
<td>
<p   align= "center "> 性别 </td>
<td>
<p   align= "center "> 年龄 </td>
<td>
<p   align= "center "> 籍贯 </td>
<td>
<p   align= "center "> 院系 </td>
<td>
<p   align= "center "> 修改 </td>
<td>
<p   align= "center "> 删除 </td>
</tr>
</table>

</div>
<%!
String   url,sql;
Connection   conn;
java.sql.Statement   stmt;
ResultSet   rs;
int   i;
%>
<%
try{
Class.forName( "com.mysql.jdbc.Driver ");
conn=DriverManager.getConnection( "jdbc:mysql://localhost:3306/university?useEncoding=true&setEncoding=gb2312 ", "root ", "147258 ");
stmt=conn.createStatement();
stmt.executeUpdate( "use   university ");
rs=stmt.executeQuery( "SELECT   *   FROM   student; ");
while(rs.next()){

rs.
%>
<div   align= "center ">
<table   border= "1 "   width= "100% "   id= "table1 ">
<tr>
<td>
<p   align= "center "> <%=new   String(((String)rs.getObject(1)).getBytes( "iso-8859-1 "), "gb2312 ")%> </td>
<td>
<p   align= "center "> <%=rs.getObject(2)%> </td>
<td>
<p   align= "center "> <%=rs.getObject(3)%> </td>
<td>
<p   align= "center "> <%=rs.getObject(4)%> </td>
<td>
<p   align= "center "> <%=rs.getObject(5)%> </td>
<td>
<p   align= "center "> <%=rs.getObject(6)%> </td>
<td>
<p   align= "center "> 修改 </td>
<td>
<p   align= "center "> 删除 </td>
</tr>
</table>

</div>
<%
}
}catch(Exception   e)
{

}

%>
<a   href= "insert.jsp "   align= "center "> 添加新纪录 </a>

这是我在JSP里调用MYSQL的源文件.MYSQL设置成gb2312,但结果还是乱码!

等待达人!

------解决方案--------------------
你把mysql设置成utf-8看看,我是这么做的没乱码
------解决方案--------------------
数据在输入的时候应该应该进行编码转换,输出的时候就不用转换了!

------解决方案--------------------
MySQL好像用的是Unicode编码,要转换编码才行,我以前也遇到过,网上有很多方法解决的。
------解决方案--------------------