【发布时间】:2012-04-12 15:42:36
【问题描述】:
我有一个 html 单选按钮。当用户单击提交按钮时,我希望将值添加到数据库表中。
有 4 个单选按钮
o a
o b
o c
o d
--- 我使用了 request.getParameter() 并引用了 q1。但是当我检查数据库表中的内容时,添加了“null”。 如何在数据库中添加值?
这是我的 html 单选按钮。
<FORM ACTION="Question2.jsp">
Q1. This is the section of code that gracefully responds to exceptions.<P>
<INPUT TYPE=RADIO NAME="q1" VALUE="a"/>a. Exception generator<BR>
<INPUT TYPE=RADIO NAME="q1" VALUE="b"/>b. Exception manipulator<BR>
<INPUT TYPE=RADIO NAME="q1" VALUE="c"/>c. Exception handler<BR>
<INPUT TYPE=RADIO NAME="q1" VALUE="d"/>d. Exception monitor<P>
<INPUT TYPE=SUBMIT VALUE="submit"/>
</FORM>
...这里我试图在表中添加值。
<%
String query = "INSERT INTO Quiz2 VALUES (?)";
PreparedStatement pst = (PreparedStatement) conn.prepareStatement(query);
String answer = request.getParameter("q1");
pst.setString(1, answer);
pst.executeUpdate();
%>
【问题讨论】:
标签: java mysql html radio-button