java - 我在使用 java 在 mysql 中插入值时遇到问题
问题描述
我有一个表单,用户从中选择一个答案,然后我取所选答案的值并在数据库中插入 3 个值,但有两个问题 1)我插入 3 行但我在 mysql 中只找到一个 2) selected_answer 值在 mysql 中始终为空,当我输入一个数字而不是 selected_answer 时,它可以工作!
<form action ="Thanks.jsp" method ="get">
<p><input type="radio" name="ans" value= <%=answers_id[0]%>/><%=answers[0]%></p>
<p><input type="radio" name="ans" value=<%=answers_id[1]%>/><%=answers[1]%></p>
<p><input type="radio" name="ans" value=<%=answers_id[2]%>/><%=answers[2]%></p>
<p><input type="submit" value="submit"/>
</form>
<%
String chosen_answer = request.getParameter("ans");
//in this loop i'm removing the chosen_answer from the array
for (int i = 0; i < answers_id.length; i++) {
if (answers_id[i] == chosen_answer) {
// shifting elements
for (int j = i; j < answers_id.length - 1; j++) {
answers_id[j] = answers_id[j + 1];
}
break;
}
}
// i will make the first aid is the answer that is chosen to know if he answer it right or wronge
String queryString3 = "INSERT INTO stud_ans VALUES("
+ "'" + ID + "',"
+ "'" + 1 + "',"
+ "'" + 7 + "') , (" + "'" + ID + "',"
+ "'" + 1 + "',"
+ "'" + 7 + "'),(" + "'" + ID + "',"
+ "'" + 1 + "',"
+ "'" + 7 + "')";
Stmt.executeUpdate(queryString3);
Con.close();
RS.close();
} catch (Exception cnfe) {
System.err.println("Exception: " + cnfe);
}
%>
解决方案
推荐阅读
- javascript - 由于没有从 express-serve-static-core 导出 ParsedQ,构建失败
- java - 我们可以在同一次运行中多次执行分区程序吗?
- python - 如何为单元测试的文件下载编写模拟
- flutter - Flutter Build Apk Error 剪贴板插件错误
- asp.net - ASP.NET Core 项目在本地系统中将项目发布到 IIS 后无法登录
- python - 为什么nix找不到python39?
- intellij-idea - 如何在 IntelliJ 中隐藏检查小部件
- kotlin - 无法使用 gradle 导入 kotlin.test.Test
- java - 不扩展 JavaPlugin
- reactjs - 基于副作用的反应测试子组件