小弟刚接触JSP不久,用JSP连结Mysql数据库时,总是出现“??”这样的乱码。在baidu上试了许多办法都尚未解决,希望各位前辈,指点一下,谢谢!
程序如下:
<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="java.sql.*" %>
<html><body bgcolor="#808000">
<%
String driver="com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/wangyonghai";
String userid="root";
String passwd="123";
try {
Class.forName(driver);
}
catch(ClassNotFoundException e){
out.println(e.getMessage());
}
try{
Connection conn=DriverManager.getConnection(url,userid,passwd);
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from resume");
while(rs.next()){
out.print(rs.getString("name"));
out.print("<hr>");
out.print("<p>");
out.print(rs.getString("homepage"));
out.print("<hr noshade>");
out.print(rs.getString("habit"));
out.print(rs.getString("home"));
}
}
catch(Exception ce){
out.println(ce.getMessage());
}
%>