收录日期:2020/11/30 12:36:37 时间:2016/05/27 05:41:38 标签:Web 开发
代码如下: 
<html> 
<head> 
<title> 航空查询 </title> 
<meta name="Generator" content="EditPlus"> 
<meta name="Author" content=""> 
<meta name="Keywords" content=""> 
<meta name="Description" content=""> 
</head> 

<body> 
<%@ page contentType="text/html;charset=GB2312"%> 
<%@ page language="java" import="java.sql.*" %> 
<%  Connection con=null; 
    Statement sql; 
ResultSet rs; 

  try 
  {Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
  }catch(ClassNotFoundException e) {} 
  try{ 
  con=DriverManager.getConnection("jdbc:odbc:airtime","sa","sa"); 
  sql=con.createStatement(); 
  
   rs=sql.executeQuery("select * from timess"); 
  }catch(Exception e){out.println(e);} 
%> 
  <table border=1 cellspacing="0" cellpadding="0" bordercolordark="#ffffff" bordercolorlight="#88a6dd" width="100%" align=center> 
<tr bgcolor="#88a6dd"> 
<td  width=100 align=center >航班号</td> 
<td  width=100 align=center>起始港</td> 
<td  width=100  align=center>终止港</td> 
<td  width=100 align=center>起始时间</td> 
<td  width=100 align=center>到达时间</td> 
<td  width=50 align=center>班期</td> 
<td  width=50 align=center>机型</td> 
<td  width=50 align=center>参考票价</td> 
<td  width=50 align=center>备注</td> 
<td  width=50 align=center>经停1</td> 
<td  width=50 align=center>经停2</td> 
</tr> 
<% while(rs.next()) 
try{ 
{out.print("<tr>"); 
out.print("<td align=center>"+rs.getString("航班号")+"</td>"); 
out.print("<td align=center>"+rs.getString("起始港")+"</td>"); 
out.print("<td align=center>"+rs.getString("终止港")+"</td>"); 
out.print("<td align=center>"+rs.getString("起始时间")+"</td>"); 
out.print("<td align=center>"+rs.getString("到达时间")+"</td>"); 
out.print("<td align=center>"+rs.getString("班期")+"</td>"); 
out.print("<td align=center>"+rs.getString("机型")+"</td>"); 
out.print("<td align=center>"+rs.getString("参考票价")+"</td>"); 
out.print("<td align=center>"+rs.getString("备注")+"</td>"); 
out.print("<td align=center>"+rs.getString("经停1")+"</td>"); 
out.print("<td align=center>"+rs.getString("经停2")+"</td>"); 

     rs.close(); 
con.close(); 
}catch(SQLException el){} 
    %> 
</body> 
</html> 
错误提示: 
exception 

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

An error occurred at line: 41 in the jsp file: /jsp.jsp 

Generated servlet error: 
    [javac] Compiling 1 source file 

J:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\_\jsp_jsp.java:95: variable rs might not have been initialized 
 while(rs.next()) 
       ^ 
1 error 


at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:130) 
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293) 
at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:353) 
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:370) 
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:473) 
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:190) 
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295) 
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247) 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193) 
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256) 
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) 
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) 
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) 
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) 
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) 
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) 
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) 
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422) 
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180) 
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) 
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171) 
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) 
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163) 
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) 
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) 
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) 
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174) 
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) 
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) 
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) 
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199) 
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828) 
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700) 
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584) 
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) 
at java.lang.Thread.run(Thread.java:534) 


请高手帮忙看一下!谢谢! 

兄弟,你好像是TOMCAT有问题哦,检察一下服务器或者是JDK
已经告诉你了:
‘ variable rs might not have been initialized ’

ResultSet rs; -> ResultSet rs=null;
Statement sql; 
ResultSet rs; 这些还是最好初始化为null好点。
还有就是你的数据库的驱动以及url的加载是否正确。
加了一句:ResultSet rs=null后又有这样的错误
description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: ResultSet is closed
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)


root cause 

javax.servlet.ServletException: ResultSet is closed
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:536)
at org.apache.jsp.jsp_jsp._jspService(jsp_jsp.java:121)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)

你的代码问题,你把rs.close()放到while()里面了,建议好好检查你的代码加上{}

飞龙中医专贴 跪求高手指点:虚拟机上网问题 有九种感情叫做爱情 散粉 字符串分割问题: 如何做一个类似于浏览器标签页的按钮 求触发器的写法,并指正错误,多谢 linux高手帮忙了, c语言Windows编程的学习 eval绑定判断的问题 smarty的load_filter问题 多文档程序点击新建文件后创建的文件没有扩展名,能设置吗? 扑克牌洗牌的图像识别 MFC中编写activeX控件的问题 怎么运行该程序啊 win32 SDK编程的时候用哪个生成工具生成了一个MFC的对话框如何把对话框给用SDK显示出来呢? 400分打开会就是满屏幕的鲜花的源代码 400分打开会就是满屏幕的鲜花的源代码 我认为就两个字符串的拼接来说+的性能完全等于StringBuilder(1.5)/StringBuffer(1.4) asp.net gif 动画图片拆分and合成 利用数组求平均值 创建表问题 如何限制用户的访问次数?只有cookies和ip吗 男女悄悄话:悲剧的开始 新婚之夜新郎变“豺狼” 一个程序的开发过程 一个奇怪的问题 按位取反问题 win32 SDK通过对话框如何将文件里面的内容给读取到EDIT里面呢? 各位大虾帮我看看这个存取款的程序 Perl编程你们都用什么IDE?