<%@ page contentType="text/html;charset=GB2312"%>
<%@ page import="java.sql.*"%>
<HTML>
<Body>
<%
   Connection con;
   Statement sql;
   ResultSet rs;
   try{class.forName("sun.jdbc.odbc.jdbcOdbcDriver");
      }
   catch(class NotFoundExcepion e){}
   try{ con=DriverManager.getConnection("jdbc:odbc:firm","","");
        sql=con.createStatement();
rs=sql.executeQuery("SELECT*from students where shuxue>=25");

System.out.print("<Table Border>");
System.out.print("<form>");
System.out.print("<TR>");
System.out.print("<Td width="100">"+"xingming" +"</td>");
        
System.out.print("<Td width="50">"+"shuxuechengji" +"</td>");
System.out.print("</TR>");
 while(rs.next()){
   System.out.print("<td>");
       System.out.print("<TD>"+rs.getString("xingming")+"</TD>");
   System.out.print("<TD>"+rs.getInt("shuxue")+"</TD>");
   System.out.print("</TR>");
   }
   System.out.print("</form>");
   System.out.print("</Table>");
           
  con.close();
   }
catch(SQLException e){}
   %>
   </BODY>
   </HTML>
报告如下错误:
org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 5 in the jsp file: /text/hehe.jsp
Generated servlet error:
D:\TOMCAT\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\text\hehe_jsp.java:51: <identifier> expected
   try{class.forName("sun.jdbc.odbc.jdbcOdbcDriver");
            ^
An error occurred at line: 5 in the jsp file: /text/hehe.jsp
Generated servlet error:
D:\TOMCAT\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\text\hehe_jsp.java:51: '{' expected
   try{class.forName("sun.jdbc.odbc.jdbcOdbcDriver");
                                                    ^
An error occurred at line: 5 in the jsp file: /text/hehe.jsp
Generated servlet error:
D:\TOMCAT\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\text\hehe_jsp.java:53: 'catch' without 'try'
   catch(classNotFoundExcepion e){}
   ^
Generated servlet error:
D:\TOMCAT\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\text\hehe_jsp.java:31: 'try' without 'catch' or 'finally'
    try {
    ^
Generated servlet error:
D:\TOMCAT\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\text\hehe_jsp.java:93: '}' expected
^
5 errors org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.请大虾们帮帮我   还是第一次连接数据库!!

解决方案 »

  1.   

    把你的 JAVA 代码改为下面的试试看:
    Connection con;
            Statement sql;
            ResultSet rs;
            try {
                Class.forName("sun.jdbc.odbc.jdbcOdbcDriver");
            } catch (ClassNotFoundException e) {
            }
            try {
                con = DriverManager.getConnection("jdbc:odbc:firm", "", "");
                sql = con.createStatement();
                rs = sql.executeQuery("SELECT*from students where shuxue>=25");            System.out.print("<Table Border>");
                System.out.print("<form>");
                System.out.print("<TR>");
                System.out.print("<Td width="100">"+"xingming" +"</td>");            System.out.print("<Td width="50">"+"shuxuechengji" +"</td>");
                System.out.print("</TR>");
                while (rs.next()) {
                    System.out.print("<td>");
                    System.out.print("<TD>" + rs.getString("xingming") + "</TD>");
                    System.out.print("<TD>" + rs.getInt("shuxue") + "</TD>");
                    System.out.print("</TR>");
                }
                System.out.print("</form>");
                System.out.print("</Table>");            con.close();
            } catch (SQLException e) {
            }
      

  2.   

    不好意思!还是不行   报错如下 :
    org.apache.jasper.JasperException: Unable to compile class for JSP
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:97)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:346)
    org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:414)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    root cause Unable to find a javac compiler;
    com.sun.tools.javac.Main is not on the classpath.
    Perhaps JAVA_HOME does not point to the JDK
    org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.getCompiler(CompilerAdapterFactory.java:106)
    org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:935)
    org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:764)
    org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:382)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)可是我的JAVA_HOME 都配置好了  
    还有就是找不到继承的类 
    Class.forName("sun.jdbc.odbc.jdbcOdbcDriver");
            } 
    catch (ClassNotFoundException e) 
    请大虾们   帮帮 !!谢谢!
      

  3.   

    打开连接字符串是:"sun.jdbc.odbc.JdbcOdbcDriver"
    不是:"sun.jdbc.odbc.jdbcOdbcDriver"
    你把JdbcOdbcDriver 写成 jdbcOdbcDriver
      

  4.   


    "sun.jdbc.odbc.jdbcOdbcDriver"

    "sun.jdbc.odbc.JdbcOdbcDriver"
    再试一下.