私は飛行会社のデータベースを作成しています。その1つの要件は、飛行機を予約するために飛行機のスケジュールを検索できるようにすることです。しかし、コードを実行するとエラーが発生します。私は何度も自分のコードを調べてみましたが、問題がどこにあるかを見つけることができません。エラーメッセージは、if(rs.next()){
という行に問題がありましたが、コードエディタを見ているときに赤い下線が表示されませんでした。代わりに、赤いアンダーラインの部分はすべて<tr>
と<td>
のタグです。JSPでデータベースを検索する
また、ユーザが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
@nitindいいえ、それはメッセージの内容の簡単な要約でした。私はSOにエラーメッセージを追加する方法を知らないし、また、エラーメッセージが何を言おうとしているのか分からない。 – Noob