【发布时间】:2017-05-21 07:21:05
【问题描述】:
我一直在为一家航空公司制作数据库,其中一项要求是允许客户搜索航班时刻表以便他们预订航班。但是,当我运行我的代码时,我不断收到错误消息。我已经尝试过多次查看我的代码,但我似乎仍然无法找出问题所在。我收到的错误消息是 if(rs.next()){ 行有问题,但是当我查看代码编辑器时它没有显示任何红色下划线。相反,带有红色下划线的部分都是我的<tr> 和<td> 标签。
另外,如果有人能教我如何为origin_airport 和destination_airport 数据字段创建一个下拉表,我将不胜感激。
这是我的代码:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Member Login</title>
</head>
<body>
<form>
<table>
<%@page import="java.sql.*" %>
<%
String user = request.getParameter("user");
out.println("Welcome, "+user);
out.println("<br>Account status: Member");
out.println("<br>What flight do you want to search for today?");
String origin=request.getParameter("origin_airport");
String dest=request.getParameter("destination_airport");
String depart=request.getParameter("departure_time");
String arrival=request.getParameter("arrival_time");
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url="jdbc:mysql://localhost/testing";
String username="root";
String password="password";
Connection conn=DriverManager.getConnection(url,username,password);
Statement st=conn.createStatement();
ResultSet rs = st.executeQuery("select * from flight_schedule where origin_airport='"+origin+"'");
ResultSet rs1 = st.executeQuery("select * from flight_schedule where destination_airport='"+dest+"'");
ResultSet rs2 = st.executeQuery("select * from flight_schedule where departure_time='"+depart+"'");
ResultSet rs3 = st.executeQuery("select * from flight_schedule where arrival_time='"+arrival+"'");
if(rs.next()){
%>
<tr><td>Origin airport: </td><td<input type="text" value="<%=rs.getString("origin_airport")%>" > </td></tr>
<tr><td>Destination airport: </td><td<input type="text" value="<%=rs1.getString("destination_airport")%>" > </td></tr>
<tr><td>Departure date: </td><td<input type="text" value="<%=rs2.getString("departure_time")%>" > </td></tr>
<tr><td>Arrival date: </td><td<input type="text" value="<%=rs3.getString("arrival_time")%>" > </td></tr>
<%
}
%>
</form>
</table>
</body>
</html>
如果有人能花时间帮助我,为我指明正确的方向,我将不胜感激。提前致谢。
Eclipse 上显示的错误信息:An exception occurred processing JSP page [/Homescreen_Member.jsp] at line [33]
错误异常:
org.apache.jasper.JasperException: An exception occurred processing JSP page [/Homescreen_Member.jsp] at line [33]
30: ResultSet rs1 = st.executeQuery("select * from flight_schedule where destination_airport='"+dest+"'");
31: ResultSet rs2 = st.executeQuery("select * from flight_schedule where departure_time='"+depart+"'");
32: ResultSet rs3 = st.executeQuery("select * from flight_schedule where arrival_time='"+arrival+"'");
33: if(rs.next()){
34: %>
35: <tr><td>Origin airport: </td><td<input type="text" value="<%=rs.getString("origin_airport")%>" > </td></tr>
36: <tr><td>Destination airport: </td><td<input type="text" value="<%=rs.getString("destination_airport")%>" > </td></tr>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:588)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
根本原因:
javax.servlet.ServletException: java.sql.SQLException: Operation not allowed after ResultSet closed
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:669)
org.apache.jsp.Homescreen_005fMember_jsp._jspService(Homescreen_005fMember_jsp.java:178)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
java.sql.SQLException: Operation not allowed after ResultSet closed
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
com.mysql.jdbc.ResultSetImpl.checkClosed(ResultSetImpl.java:743)
com.mysql.jdbc.ResultSetImpl.next(ResultSetImpl.java:6303)
org.apache.jsp.Homescreen_005fMember_jsp._jspService(Homescreen_005fMember_jsp.java:142)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
【问题讨论】:
-
“线路有问题”是实际消息吗?如果不是,实际的错误信息是什么?
-
@nitind 不,这是对消息内容的简短摘要。我不知道如何在 SO 上添加错误消息,而且我不明白错误消息的意思。
标签: html mysql database eclipse jsp