变量的值正在变化

时间:2019-05-25 17:15:06

标签: java servlets java-ee

我正在将CQM插入数据库,首先插入考试坐标并检索其ID,然后插入其问题的标题和内容并检索其ID,然后它就可以工作了。

问题是当我插入命题时:例如,如果问题的id为7,则将其更改为0 ,并且插入失败

这是我的servlet

    Examen examen = (Examen) request.getSession().getAttribute("examen");
    int id_examen = ExamDAO.ajouter_examen(examen);

    Question quest = new Question(titre, contenu, id_examen);
    int id_question = ExamDAO.ajouter_question(quest);
    System.out.println("id_question " + id_question);

//// the problem is here !!
    Question prop = new Question(id_question, propositions);
    int propu = ExamDAO.ajouter_prop(prop);
    System.out.println(prop);

数据库代码

public static int ajouter_prop(Question prop) {
    Connection cnx;
    int propKey = 0;

    try {
        cnx = Connect.getConnection();
        cnx.setAutoCommit(false);

        String req = "insert into prop(id_question, contenu) values(?,?)";

        PreparedStatement st = cnx.prepareStatement(req);
        st.setInt(1, prop.getIdQuiz());

        for (Proposition propp : prop.getListProp()) {
            st.setString(2, propp.getContenu());
            st.addBatch();
        }

        st.executeBatch();

0 个答案:

没有答案