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(); }