我的代码是
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.util.*,java.io.*"%>
<html>
<body>
<table border=1>
<tr><td>ID</td><td>书名</td><td>出版社</td><td>价格</td></tr>
<%! String trans(String chi)
{
               String result = null;
               byte temp [];
               try
               {
                       temp=chi.getBytes("iso-8859-1");
                      result = new String(temp);
                }
                catch(UnsupportedEncodingException e)
                {
                        System.out.println (e.toString());
                }
return result;
}
%>
<%   Class.forName("com.jdbc.mysql.Driver").newInstance();
   Connection con=java.sql.DriverManager.getConnection("jdbc:mysql://localhost/web","root","51401991");
   Statement stmt=con.createStatement();
    ResultSet rst=stmt.executeQuery("select * from user");
    while(rst.next())
    {
    out.println("<tr>");
    out.println("<td>"+rst.getString("userName")+"</td>");
    out.println("<td>"+trans(rst.getString("regTime"))+"</td>");
    out.println("<td>"+trans(rst.getString("email"))+"</td>");
    out.println("</tr>");
    }
    //关闭连接、释放资源
    rst.close();
    stmt.close();
    con.close();
    %>
</table>
</body>
</html>
总是报错:org.apache.jasper.JasperException: An exception occurred processing JSP page /mysql.jsp at line “Class.forName("com.jdbc.mysql.Driver").newInstance();”
我用java程序可以正常访问,但用jsp就出错

解决方案 »

  1.   

    连接方法
    Class.forName("com.jdbc.mysql.Driver");
    Connection con=java.sql.DriverManager.getConnection("jdbc:mysql://localhost/web","root","51401991");
      

  2.   

    还有,你的驱动包是加到项目中的lib了吧。
      

  3.   

    感谢各位,我把"com.jdbc.mysql.Driver"改成"org.gjt.mm.mysql.Driver",并且去掉了newInstance(),结果对了
      

  4.   

    newInstance()应该不影响吧……还有localhost后面不用加端口号也可以吗?
      

  5.   

    哦,的确,newInstance()不影响。我没加端口可以,不知道是不是因为在单机上的缘故