package jp.ac.kcska.questionsystem.questionmanager.horizon; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; public class GetQuestionList { private Connection getConnection() throws SQLException { Connection connection = null; connection = DriverManager.getConnection( "jdbc:mysql://localhost/questionsystem","root","mysql"); connection.setAutoCommit(false); return connection; } public ArrayList getList(){ ArrayList questionList = new ArrayList(); try { Connection connection = getConnection(); PreparedStatement statement = null; ResultSet resultSet = null; String strSQL = "SELECT * FROM mst_question"; statement = connection.prepareStatement(strSQL); resultSet = statement.executeQuery(); while (resultSet.next()) { Mst_questionVo questionVo = new Mst_questionVo(); int id = resultSet.getInt("id"); int categoryid = resultSet.getInt("categoryid"); int fieldid = resultSet.getInt("fieldid"); String sentence = resultSet.getString("sentence"); int imageid = resultSet.getInt("imageid"); int examid = resultSet.getInt("examid"); questionVo.setId(id); questionVo.setCategoryid(categoryid); questionVo.setFieldid(fieldid); questionVo.setSentence(sentence); questionVo.setImageid(imageid); questionVo.setExamid(examid); questionList.add(questionVo); } } catch (SQLException e) { e.printStackTrace(); } return questionList; } }