我在使用Java在mysql中插入值时遇到问题

时间:2019-11-11 09:15:36

标签: java mysql jsp

我有一个表格,用户从中选择一个答案,然后我将选择的答案的值插入数据库中的3个值,但是有两个问题1)我插入了3行,但是我在mysql中只找到一个2)在mysql中,selected_answer值始终为空,当我输入数字而不是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);
    }


%>

0 个答案:

没有答案