在下圖中,當用戶按下提交按鈕時,應用程序將選擇的數字插入到數據庫中。但它不適用於activityid號碼。按提交按鈕後,activityid返回null並且返回選擇的數字。我該怎麼辦插入正確activityid數據庫檢索數據並插入數據庫
music.jsp
<table border="1" width="30%" height="30%">
<th><font color='#D18603'>ActivityID</font>
<th><font color='#D18603'>Type</font></th>
<th><font color='#D18603'>Description</font></th>
<th><font color='#D18603'>City</font></th>
<th><font color='#D18603'>Location</font></th>
<th><font color='#D18603'>Date</font></th>
<th><font color='#D18603'>Price</font></th>
<th><font color='#D18603'>Buy</font>
<%
Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/users", "users", "123");
Statement st = con.createStatement();
ResultSet rs;
rs = st.executeQuery("select * from activities where type='müzik'");
while (rs.next()) {
out.println("<tr>");
out.println("<td>" + rs.getString("id")+"</td>");
out.println("<td>" + rs.getString("type")+ "</td>");
out.println("<td>" + rs.getString("description")+ "</td>");
out.println("<td>" + rs.getString("city") + "</td>");
out.println("<td>" + rs.getString("location")+ "</td>");
out.println("<td>" + rs.getString("date") + "</td>");
out.println("<td>" + rs.getString("price") + "</td>");
out.println("<td><b><form action='reservations.jsp'><select name='buy'><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option><option value='5'>5</option></select><input type='submit' value='Submit'></form></b>");
out.println("</tr>");
}
st.close();
%>
Reservation.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import ="java.sql.*" %>
<%
String username = (String) request.getSession().getAttribute("username");
Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/users", "users", "123");
String sorgu = "INSERT INTO reservation(id,username,buy) VALUES ('" + request.getParameter("id") + "', '" + username + "','" + request.getParameter("buy") + "') ";
java.sql.Statement st = con.createStatement();
int rowNum = st.executeUpdate(sorgu);
response.sendRedirect("paypal.html");
st.close();
%>
我沒有看到您分配一個名稱ActivityId列將其作爲參數傳遞給它。 –
是的。這就是問題。我怎樣才能做到這一點 ?我搜索了谷歌,但icannot找到。這是我的解決方案,你能幫我嗎? – tripley