Class.forName("org.gjt.mm.mysql.Driver").newInstance();
改为
Class.forName("org.gjt.mm.mysql.Driver");
试试

解决方案 »

  1.   

    我将mm.mysql中的mm.mysql-2.0.14.jar拷贝到c:\TOMCAT4\bin目录下,并将C:\mm.mysql驱动目录org拷贝到我的C:\TOMCAT4\server\class\目录中。就能显示出来了!我可以连接数据库了!于是我就修改加入我的另一段代码。
    <%@ page contentType="text/html;charset=gb2312" %>
    <%@ page language="java" import="java.sql.*" %>
    <%@ page language="java" import="/bbs/forumbeans.Linkdb.class" %>
    <%@ include file="header.htm"%>
    <script language="JavaScript">
    function isValid(loginform){
        if(loginform.username.value==""){
            alert("登录名称不能为空!");
    return false;
        }
        else if((loginform.password.value.length<3)||(loginform.password.value.length>8)){
            alert("密码必须是3-8位字母或数字!");
    return false;
        }
        else {
            return true;
        }
    }
     function pop(pageurl) { 
      window.open(pageurl,"member","toolbar=no,location=no,status=no,menubar=no,resizable=no,width=500,height=400"); 
     } 
    </script><jsp:useBean id="linkdb" scope="page" class="forumbeans.Linkdb" />
    <% 
      //所有主题数
      int intCountAllTopic=0;
      ResultSet CountAllTopicrs = linkdb.executeQuery("select count(*) as CountAllTopic from post Where post_id=0");
      if (CountAllTopicrs.next()) 
        intCountAllTopic = CountAllTopicrs.getInt("CountAllTopic");
      CountAllTopicrs.close();
      //所有帖子数
      int intCountAllPost=0;
      ResultSet CountAllPostrs = linkdb.executeQuery("select count(*) as CountAllPost from post");
      if (CountAllPostrs.next()) 
        intCountAllPost= CountAllPostrs.getInt("CountAllPost");
      CountAllPostrs.close();
      //注册会员总数。
      int intCountAllMember=0;
      ResultSet CountAllMemberrs = linkdb.executeQuery("select count(*) as CountAllMember from member");
      if (CountAllMemberrs.next()) 
        intCountAllMember= CountAllMemberrs.getInt("CountAllMember");
      CountAllMemberrs.close();
      //最新加入会员。
      String strNewMember="";
      int intNewMember=1;
      ResultSet NewMemberRs=linkdb.executeQuery("select id,username from member order by id desc limit 1");
      if (NewMemberRs.next()){
        strNewMember=NewMemberRs.getString("username");
    intNewMember=NewMemberRs.getInt("id");
      }
      NewMemberRs.close();   //获取username的Session值。
       String username = (String) session.getAttribute("username");  
       if (username==null) username="";
       String dlname = request.getParameter("username");  
       if (dlname==null) dlname="";   if (username!=null&&username!="")
       {
    %>
    <table border=0 width=100%> 
    <tr>
     <td width=60%>
    &nbsp;&nbsp;&nbsp;&nbsp;Hello,<font color="red"><%=username%></font>,欢迎光临JSP论坛,在这里你可以发表新帖或回复帖子,如果你的经验到达一定的程度,你相应的头衔还会改变!如果你是斑竹,还有管理权限。好好努力哦
    </td>
    <td width=40%>
          <table border=0 align="right">
           <tr>
            <td align="right">
              <%=username%>,欢迎你到JSP论坛社区
            </td> 
          </tr>
          <tr>
            <td>
              主题总数:<%=intCountAllTopic%> | 发帖总数:<%=intCountAllPost%> | 注册会员数:<%=intCountAllMember%>
            </td>
          </tr>
      <tr>
        <td align="right">
          欢迎我们的新会员:<a onclick=pop("member.jsp?id=<%=intNewMember%>")><font color="#2F8BDF"><%=strNewMember%></font>
        </td>
      </tr>
         </table>
    </td>
      </table>
    <%
       }
       else if (dlname!=""&&dlname!=null)
       {
        String password = request.getParameter("password");  
        int intCountInto=0;
    String strIntoForum;
        ResultSet CountIntoRs = linkdb.executeQuery("select intoforum from member where username='"+dlname+"'and password='"+password+"' ");
        if (CountIntoRs.next())

     session.putValue("username",dlname);  //设置username的Session
     session.putValue("password",password);  //设置password的Session
        //初始化CountIntoRs.getString("intoforum"),不然会出现NumberFormatException的错误。
     strIntoForum=CountIntoRs.getString("intoforum");
         if (strIntoForum==null)        
        strIntoForum="0";
         intCountInto = Integer.parseInt(strIntoForum)+1;
         linkdb.executeUpdate("Update member set intoforum= "+intCountInto+" where username='"+dlname+"' ");
    %>
     <table width=100% border=0> 
    <tr>
      <td width=60% align="center">
         Hello,<font color="red"><%=dlname%></font>,欢迎你第<%=intCountInto%>次光临JSP论坛!<br>
     <td>
         <td width=40%>
          <table border=0 align="right">
           <tr>
            <td align="right">
              <%=username%>,欢迎你到JSP论坛社区
            </td> 
          </tr>
          <tr>
            <td>
              主题总数:<%=intCountAllTopic%> | 发帖总数:<%=intCountAllPost%> | 注册会员数:<%=intCountAllMember%>
            </td>
          </tr>
      <tr>
        <td align="right">
          欢迎我们的新会员:<a onclick=pop("member.jsp?id=<%=intNewMember%>")><font color="#2F8BDF"><%=strNewMember%></font>
        </td>
      </tr>
         </table>
         </td>
       </tr>
    </table>
    <%
    }
    else
        {
    %>
      <script language="JavaScript">
         alert("对不起,数据库中没有此用户名或者你的密码输入错误,请确定后重新登录!");
      </script>
    如果你忘记了密码,请和<A HREF="mailto:[email protected]">系统管理员</A>联系!
    <center><a href="JavaScript:history.back()">返回修改</a></center>
    <%
    }
       }
       else
       {
    %>
    <table width=100%>
    <tr>
     <td width="60%" align="left">  
       <FORM METHOD=POST  action="index.jsp" onSubmit="return isValid(this);">
       <table border=0 cellpadding=0 border=0 cellspacing=1 width=100%>
       <tr>
        <td width=20%>用户名:</td>
        <td><INPUT TYPE="TEXT" NAME="username" VALUE="<%=username%>" SIZE=10 MAXLENGTH=25 
       > </td><td width=20%>
       密 码:</td>
       <td><INPUT TYPE="password" NAME="password" SIZE=10 MAXLENGTH=13> 
       </td>
       <td  width=20%>
       <INPUT TYPE="Submit" NAME="SUBMIT" VALUE="登 录"></td>
       <td  width=40%>请在此<A HREF="register.jsp">注册</a>。</td>
    </tr>
      </table>
       </form>
    </td>
      

  2.   

    <td width=40%>
          <table border=0 align="right">
           <tr>
            <td align="right">
              你还未登录,请先登录
            </td> 
          </tr>
          <tr>
            <td>
              主题总数:<%=intCountAllTopic%> | 发帖总数:<%=intCountAllPost%> | 注册会员数:<%=intCountAllMember%>
            </td>
          </tr>
      <tr>
        <td align="right">
          欢迎我们的新会员:<a onclick=pop("member.jsp?id=<%=intNewMember%>")><font color="#2F8BDF"><%=strNewMember%></font>
        </td>
      </tr>
         </table>
      </td>
    </tr>
    </table>
    <%
       }
    %><br>
    <body bgcolor="#FFFFFF" text="#000000" link="#004080" vlink="#004080" id=all><table cellpadding=4 cellspacing=1 border=1 width="100%" bordercolordark='#EAF0FF' bordercolorlight='#000000' bordercolor='#000000'>
      <tr bgcolor="#007CD3"><td align=center><font COLOR="#FFFFFF">序号</font></td>
      <td valign=bottom align=center><font COLOR="#FFFFFF">论坛</font></td>
      <td NOWRAP valign=bottom align=center><font COLOR="#FFFFFF">发贴数</font></td>
      <td NOWRAP valign=bottom align=center><font COLOR="#FFFFFF">主题数</font></td>
      <td NOWRAP valign=bottom align=center><font COLOR="#FFFFFF">最新发表</font></td>
      <td valign=bottom align=center><font COLOR="#FFFFFF">斑竹</font></td></tr>
    <%
      String strDesc="";
      int intDescId;
      ResultSet descrs=linkdb.executeQuery("select * from description order by descid");
      while (descrs.next())
      {
        strDesc=descrs.getString("desctext");
    intDescId=descrs.getInt("descid");
    %>
      <TR bgcolor="c0c0c0"><td colspan=6>
      <font color="#000000"><%=strDesc%></a></font></td>
      </tr>
    <%
        ResultSet rs = linkdb.executeQuery("select b.descid,a.* from project a,description b where a.descid=b.descid and b.descid="+intDescId+" order by a.descid,a.forum_id");
        int intForum_id;
        String strProject;
        String strDescription; 
        String strMaster="";
        while (rs.next()) {
          intForum_id = Integer.parseInt(rs.getString("forum_id"));
          strProject = rs.getString("project");
          strDescription = rs.getString("description");
          strMaster= rs.getString("master");
    %>
      <tr>
        <td NOWRAP align=center width="6%"><font size=2><%=intForum_id%></font></td>
        <td NOWRAP valign=bottom width="49%"> <table border=0><tr><td><font size=2><a href='forumdisplay.jsp?forum_id=<%=intForum_id%>'><%=strProject%></a></font></td></tr>
    <tr><td><font size=2><%=strDescription%></font></td></tr></table> </td><% 
    int userid=1;
        ResultSet UserZlRs=linkdb.executeQuery("select id from member where username='"+username+"'");
    if (UserZlRs.next())
    {
             userid=UserZlRs.getInt("id");
    }  //总的帖子数
      int intCountPost;
      ResultSet CountPostrs = linkdb.executeQuery("select count(*) as CountPost from post Where forum_id="+intForum_id);
      if (CountPostrs.next()) 
        intCountPost = CountPostrs.getInt("CountPost");
      else
        intCountPost=0;
      CountPostrs.close(); //总的主题数
      int intCountTopic=0;
      ResultSet CountTopicrs = linkdb.executeQuery("select count(*) as CountTopic from post Where forum_id="+intForum_id+" and post_id=0");
      if (CountTopicrs.next()) 
        intCountTopic = CountTopicrs.getInt("CountTopic");
      CountTopicrs.close();  //最后发表
      String lastposttime="";
      ResultSet LastPostRs = linkdb.executeQuery("select max(posttime) as LastPost from post Where forum_id="+intForum_id);
      if (LastPostRs.next()) {
        lastposttime = LastPostRs.getString("LastPost");
    if (lastposttime==null||lastposttime=="") lastposttime="暂无发表";
      }
      LastPostRs.close();  //最后发表的作者和心情图片。
      String lastpostname="";
      String lastpostpic="";
      int lastUserId=1;
      ResultSet LastPostUserRs=null;
      ResultSet LastPostOtherRs = linkdb.executeQuery("select username,picture from post Where forum_id="+intForum_id+" and posttime='"+lastposttime+"'");
      if (LastPostOtherRs.next()) {
        lastpostname = LastPostOtherRs.getString("username");
        lastpostpic = LastPostOtherRs.getString("picture");
        LastPostUserRs=linkdb.executeQuery("select id from member where username='"+lastpostname+"'");
    if (LastPostUserRs.next()){ lastUserId=LastPostUserRs.getInt("id");}
    }
    %>
        <td NOWRAP align=center width="5%"><font size=2><%=intCountPost%></font></td>
        <td NOWRAP align=center width="5%"><font size=2><%=intCountTopic%></font></td>
        <td NOWRAP align=center width="20%"><font size=2>
    <% if(lastpostname==null||lastpostname==""){%>
    暂无发表
    <%}else{%>
    作者:<font size=2><a onclick=pop("member.jsp?id=<%=lastUserId%>")><font color="#2F8BDF"><%=lastpostname%></a></font><br><img src="<%=lastpostpic%>"><%=lastposttime%>
    <%}%>
    </font></td>
        <td NOWRAP align=center width="15%"><font size=2>
    <%=strMaster%></font></td>
      </tr>
    <%
      }
      rs.close();
    }
    %>
    </table>
    <br>
    <a href="managelogin.jsp">管理入口</a>[管理员、班竹专用]
    <br>
    <br>
    <br>
    <%@ include file="footer.htm"%>
      

  3.   

    我的JAVA包Linkdb.class文件是:
    package forumbeans;import java.sql.*;public class Linkdb {
      String strDriver="org.gjt.mm.mysql.Driver";
      String strConn="jdbc:mysql://mysql/forum?user=zl&password=zl2&useUnicode=true&characterEncoding=8859_1";
      private Connection conn = null;
      private Statement stmt = null;
      ResultSet rs = null;  public Linkdb() 
      {
       //连接MySql_jdbc驱动程序
    try { 
             Class.forName(strDriver); 
            } catch (Exception E) { 
                System.err.println("不能连接MySql数据库!"); 
              } 
      }
    //执行Select语句
      public ResultSet executeQuery(String sql) {
        rs = null;
        try {
          conn = DriverManager.getConnection(strConn); 
          stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
          rs = stmt.executeQuery(sql);
           }catch(SQLException ex) { 
              System.err.println("执行SQL语句出错:" + ex.getMessage());
           }
        return rs;
      } //执行Insert,Update语句 
      public void executeUpdate(String sql) {
        stmt = null;
        rs=null;
        try {
        conn = DriverManager.getConnection(strConn); 
        stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
        stmt.executeQuery(sql);
        stmt.close();
        conn.close();
        } 
        catch(SQLException ex) { 
          System.err.println("执行SQL语句出错: " + ex.getMessage());
        }
      }  public void closeStmt(){
        try{
          stmt.close();
         }
        catch(SQLException e){
          e.printStackTrace();
         }
      }  public void closeConn(){
        try{
          conn.close();
         }
        catch(SQLException e){
          e.printStackTrace();
         }
      }
    }
      

  4.   

    一个JSP调用JAVA BEANS实现对数据库的操作,看上去没什么问题。
    不知道你要问什么??
      

  5.   

    这个论坛连续发贴不能超多三份,我才知道,所以我出现的问题还没有提出,就不让我在回复了。谢谢你的支持!我在IE中是错误是这样的!在IE中出现问题是提示是:
    type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.compiler.CompileException: /bbs/index.jsp(2,0) Page directive: can't have multiple occurrences of language
    at org.apache.jasper.compiler.JspParseEventListener$LanguageHandler.handlePageDirectiveAttribute(Unknown Source)
    at org.apache.jasper.compiler.JspParseEventListener.handleDirective(Unknown Source)
    at org.apache.jasper.compiler.DelegatingListener.handleDirective(Unknown Source)
    at org.apache.jasper.compiler.Parser$Directive.accept(Unknown Source)
    at org.apache.jasper.compiler.Parser.parse(Unknown Source)
    at org.apache.jasper.compiler.Parser.parse(Unknown Source)
    at org.apache.jasper.compiler.Parser.parse(Unknown Source)
    at org.apache.jasper.compiler.ParserController.parse(Unknown Source)
    at org.apache.jasper.compiler.Compiler.compile(Unknown Source)
    at org.apache.jasper.servlet.JspServlet.loadJSP(Unknown Source)
    at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(Unknown Source)
    at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(Unknown Source)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(Unknown Source)
    at org.apache.jasper.servlet.JspServlet.service(Unknown Source)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source)
    at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
    at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
    at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
    at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
    at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
    at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
    at org.apache.catalina.core.StandardContext.invoke(Unknown Source)
    at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
    at org.apache.catalina.valves.ErrorDispatcherValve.invoke(Unknown Source)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
    at org.apache.catalina.valves.ErrorReportValve.invoke(Unknown Source)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
    at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
    at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
    at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
    at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
    at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
    at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:381)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:356)
    at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:495)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:518)
    at java.lang.Thread.run(Thread.java:484)请问我那里出错了!请帮我看看好吗?我知道程序很多,很不好读!希望大家帮我看看!谢谢了!
      

  6.   

    问题出在这里
    <%@ page contentType="text/html;charset=gb2312" %>
    <%@ page language="java" import="java.sql.*" %>
    <%@ page language="java" import="/bbs/forumbeans.Linkdb.class" %>
    <%@ include file="header.htm"%>你只能用一次language="java"通常Exception 的第一句是出错的关键,就象上面的
    "org.apache.jasper.compiler.CompileException: /bbs/index.jsp(2,0) Page directive: can't have multiple occurrences of language"