public TestSpecif findTestSpecif(int testIdVal) { int tempTestIdVal = 0; List<Integer> idTestSpecValue = new ArrayList<Integer>(); List<Integer> questionIdList = new ArrayList<Integer>(); try { Connection cn = pool.getConnection(); PreparedStatement st = null; try { st = cn.prepareStatement(Resource.getDBProperties("query.testspec.find")); st.setInt(1, testIdVal); ResultSet rs = null; try { rs = st.executeQuery(); while (rs.next()) { tempTestIdVal = rs.getInt(Resource.getDBProperties("testsquestions.field.idtest")); idTestSpecValue.add( rs.getInt(Resource.getDBProperties("testsquestions.field.idtestquest"))); questionIdList.add( rs.getInt(Resource.getDBProperties("testsquestions.field.idquestion"))); } } finally { if (rs != null) rs.close(); else logger.error(Resource.getStrErr("error.notload.result")); } } finally { if (st != null) st.close(); else logger.error(Resource.getStrErr("error.notload.statement")); } } catch (SQLException e) { logger.error(e); } pool.close(); return new TestSpecif(idTestSpecValue, tempTestIdVal, questionIdList); }
public void insertTestSpecif(int testIdVal, int[] questionIdListVal) { try { Connection cn = pool.getConnection(); PreparedStatement st = null; try { for (int i = 0; i < questionIdListVal.length; i++) { st = cn.prepareStatement(Resource.getDBProperties("query.testspec.insert")); st.setInt(1, testIdVal); st.setInt(2, questionIdListVal[i]); st.executeUpdate(); } } finally { if (st != null) st.close(); else logger.error(Resource.getStrErr("error.notload.statement")); } } catch (SQLException e) { logger.error(e); } pool.close(); }
public static boolean addUser( String login, String password, String lastname, String firstname, String accesstype, String role) throws UnsupportedEncodingException, ClassNotFoundException { boolean additionResult = false; if (role.equals(Resource.getJspParams("param.register.usertype.tutor"))) { String currPost = ""; for (int i = 0; i < 4; i++) { if (accesstype.equals(Resource.getJspParams("param.testcreate.avar") + i)) { currPost = new String( Resource.getJspParams("param.register.accesoryvar" + (i + 1) + ".tutor") .getBytes("ISO-8859-1"), "UTF-8"); } } TutorDAO currentTutor = mysqlFactory.getTutorDAO(); additionResult = currentTutor.insertTutor(lastname, firstname, currPost, login, password); } else if (role.equals(Resource.getJspParams("param.register.usertype.student"))) { String currGroup = ""; for (int i = 0; i < 4; i++) { if (accesstype.equals(Resource.getJspParams("param.testcreate.avar") + i)) { currGroup = new String( Resource.getJspParams("param.register.accesoryvar" + (i + 1) + ".student") .getBytes("ISO-8859-1"), "UTF-8"); } } StudentDAO currentStudent = mysqlFactory.getStudentDAO(); additionResult = currentStudent.insertStudent(lastname, firstname, currGroup, login, password); } return additionResult; }