回 帖 发 新 帖 刷新版面

主题:一个菜鸟的烦恼

我按照书上一步一步作的 但还是不幸的出问题了!
代码如下:
<%@ 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(ClassNotFoundException e)
           {
               out.print("类找不到!")
           }
             try
             {
               con=DriverManager.gerConnection("jdbc:odbc:host");
               sql=con.createStatement();
              rs=sql.executeQuery("SELECT * FROM guests");
               out.print("<Table Border>");
               out.print("<TR><td colspan=8 align=center>客户数据</td></tr>");
               out.print("<TR>");
                   out.print("<td width=50>"+"姓名");
                   out.print("<td width=50>"+"现住房间号");
                   out.print("<td width=50>"+"性别");
                   out.print("<td width=50>"+"证件类别");
                   out.print("<td width=50>"+"证件号");
                   out.print("<td width=50>"+"国家编号");
                   out.print("<td width=50>"+"到达日期");
                   out.print("<td width=50>"+"离开日期");
                   out.print("<td width=50>"+"押金");
               out.print("</TR>");
              while(rs.next())
              {
                 out.print("<TR>");
                    out.print("<TD>"+rs.getString("name"));
                    out.print("<TD>"+rs.getString("roomcode"));
                    out.print("<TD>"+rs.getString("sex"));
                    out.print("<TD>"+rs.getString("certclassno"));
                    out.print("<TD>"+rs.getString("certificate"));
                    out.print("<TD>"+rs.getString("countryno"));
                    out.print("<TD>"+rs.getString("arridate"));
                    out.print("<TD>"+rs.getString("leftdate"));
                    out.print("<TD>"+rs.getString("price"));
                 out.print("</TR>");
               }
               out.print("</table>");
               con.close();
            }
          catch(SQLException e1)
          {
              out.print("SQL 异常!")
          }
          %>
        </body>
    </html>
    
    
    错误提示如下:
    type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 5 in the jsp file: /selectGustesTable.jsp
Generated servlet error:
Syntax error on token "class", invalid Expression

An error occurred at line: 5 in the jsp file: /selectGustesTable.jsp
Generated servlet error:
Syntax error, insert ";" to complete BlockStatements

An error occurred at line: 5 in the jsp file: /selectGustesTable.jsp
Generated servlet error:
Syntax error on token "Invalid Character", invalid AssignmentOperator

An error occurred at line: 5 in the jsp file: /selectGustesTable.jsp
Generated servlet error:
Syntax error on token "Invalid Character", ; expected

An error occurred at line: 5 in the jsp file: /selectGustesTable.jsp
Generated servlet error:
Syntax error on token "Invalid Character", invalid AssignmentOperator

An error occurred at line: 5 in the jsp file: /selectGustesTable.jsp
Generated servlet error:
Syntax error on token "Invalid Character", ; expected

An error occurred at line: 5 in the jsp file: /selectGustesTable.jsp
Generated servlet error:
Syntax error on token "Invalid Character", invalid AssignmentOperator

An error occurred at line: 5 in the jsp file: /selectGustesTable.jsp
Generated servlet error:
Syntax error on token "Invalid Character", ; expected

An error occurred at line: 5 in the jsp file: /selectGustesTable.jsp
Generated servlet error:
Syntax error on token "Invalid Character", invalid AssignmentOperator

An error occurred at line: 5 in the jsp file: /selectGustesTable.jsp
Generated servlet error:
Syntax error on token "Invalid Character", ; expected

An error occurred at line: 5 in the jsp file: /selectGustesTable.jsp
Generated servlet error:
Syntax error on token "Invalid Character", invalid AssignmentOperator

An error occurred at line: 5 in the jsp file: /selectGustesTable.jsp
Generated servlet error:
Syntax error, insert ";" to complete BlockStatements


    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:409)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.12 logs.

信心被沉重打击啊!!!
大家帮帮这个可怜的菜鸟把!

回复列表 (共8个回复)

沙发

con=DriverManager.gerConnection("jdbc:odbc:host");
gerConnection这个都拼错了

板凳

[quote]con=DriverManager.gerConnection("jdbc:odbc:host");
gerConnection这个都拼错了[/quote]
改过来了 单还是一样啊

3 楼

<%@ 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(ClassNotFoundException e)
           {
               out.print("类找不到!");
           }
             try
             {
               con=DriverManager.getConnection("jdbc:odbc:host");
               sql=con.createStatement();
              rs=sql.executeQuery("SELECT * FROM guests");
               out.print("<Table Border>");
               out.print("<TR><td colspan=8 align=center>客户数据</td></tr>");
               out.print("<TR>");
                   out.print("<td width=50>"+"姓名</td>");
                   out.print("<td width=50>"+"现住房间号</td>");
                   out.print("<td width=50>"+"性别</td>");
                   out.print("<td width=50>"+"证件类别</td>");
                   out.print("<td width=50>"+"证件号</td>");
                   out.print("<td width=50>"+"国家编号</td>");
                   out.print("<td width=50>"+"到达日期</td>");
                   out.print("<td width=50>"+"离开日期</td>");
                   out.print("<td width=50>"+"押金</td>");
               out.print("</TR>");
              while(rs.next())
              {
                 out.print("<TR>");
                    out.print("<TD>"+rs.getString("name"));
                    out.print("<TD>"+rs.getString("roomcode"));
                    out.print("<TD>"+rs.getString("sex"));
                    out.print("<TD>"+rs.getString("certclassno"));
                    out.print("<TD>"+rs.getString("certificate"));
                    out.print("<TD>"+rs.getString("countryno"));
                    out.print("<TD>"+rs.getString("arridate"));
                    out.print("<TD>"+rs.getString("leftdate"));
                    out.print("<TD>"+rs.getString("price"));
                 out.print("</TR>");
               }
               out.print("</table>");
               con.close();
            }
          catch(SQLException e1)
          {
              out.print("SQL 异常!");
          }
          %>
        </body>
    </html>

楼主都没有检查错误. 这个试试

4 楼


它打应那个SQL异常,呵呵 谢谢啊 比以前好多了

5 楼

[quote]<%@ 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(ClassNotFoundException e)
           {
               out.print("类找不到!");
           }
             try
             {
               con=DriverManager.getConnection("jdbc:odbc:host");
               sql=con.createStatement();
              rs=sql.executeQuery("SELECT * FROM guests");
               out.print("<Table Border>");
               out.print("<TR><td colspan=8 align=center>客户数据</td></tr>");
               out.print("<TR>");
                   out.print("<td width=50>"+"姓名</td>");
                   out.print("<td width=50>"+"现住房间号</td>");
                   out.print("<td width=50>"+"性别</td>");
                   out.print("<td width=50>"+"证件类别</td>");
                   out.print("<td width=50>"+"证件号</td>");
                   out.print("<td width=50>"+"国家编号</td>");
                   out.print("<td width=50>"+"到达日期</td>");
                   out.print("<td width=50>"+"离开日期</td>");
                   out.print("<td width=50>"+"押金</td>");
               out.print("</TR>");
              while(rs.next())
              {
                 out.print("<TR>");
                    out.print("<TD>"+rs.getString("name"));
                    out.print("<TD>"+rs.getString("roomcode"));
                    out.print("<TD>"+rs.getString("sex"));
                    out.print("<TD>"+rs.getString("certclassno"));
                    out.print("<TD>"+rs.getString("certificate"));
                    out.print("<TD>"+rs.getString("countryno"));
                    out.print("<TD>"+rs.getString("arridate"));
                    out.print("<TD>"+rs.getString("leftdate"));
                    out.print("<TD>"+rs.getString("price"));
                 out.print("</TR>");
               }
               out.print("</table>");
               con.close();
            }
          catch(SQLException e1)
          {
              out.print("SQL 异常!");
          }
          %>
        </body>
    </html>

楼主都没有检查错误. 这个试试[/quote]
可以问以下你改那了吗 我看了半天没看到啊 

6 楼

class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

还有代码中的有些分号要在英文输入状态下输入,

认真照着书的的代码打,不要粗心

7 楼

[quote]class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

还有代码中的有些分号要在英文输入状态下输入,

认真照着书的的代码打,不要粗心[/quote]
我敲的是英文状态下的啊

8 楼

con=DriverManager.gerConnection("jdbc:odbc:host");
其中,host是数据源的名字,你有没有在控制面板里建该数据源???

我来回复

您尚未登录,请登录后再回复。点此登录或注册