package jp.ac.kcska.questionsystem.usermanager.horizon; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; import java.util.ArrayList; import jp.ac.kcska.questionsystem.Mst_userVo; public class GetUserList { 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 userList = new ArrayList(); try { Connection connection = getConnection(); PreparedStatement statement = null; ResultSet resultSet = null; String strSQL = "SELECT * FROM mst_user"; statement = connection.prepareStatement(strSQL); resultSet = statement.executeQuery(); while (resultSet.next()) { Mst_userVo userVo = new Mst_userVo(); int no = resultSet.getInt("no"); String username = resultSet.getString("username"); String password = resultSet.getString("password"); Timestamp lastlogindate = resultSet.getTimestamp("lastlogindate"); byte adminFlag = resultSet.getByte("adminFlag"); userVo.setId(no); userVo.setUsername(username); userVo.setLastlogindate(lastlogindate); userVo.setPassword(password); userVo.setAdminflag(adminFlag); userList.add(userVo); } } catch (SQLException e) { e.printStackTrace(); } return userList; } }