package jp.ac.kcska.questionsystem.usermanager.horizon; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Iterator; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import jp.ac.kcska.questionsystem.Mst_userVo; public class EditUserServlet extends HttpServlet { private static final long serialVersionUID = 1L; @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String paramValue = req.getParameter("primary"); int no = Integer.parseInt(paramValue); Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; HttpSession session = req.getSession(); try { connection = DriverManager.getConnection( "jdbc:mysql://localhost/questionsystem", "root", "mysql"); statement = connection .prepareStatement("SELECT * FROM MST_USER WHERE no = ?"); statement.setInt(1, no); resultSet = statement.executeQuery(); while (resultSet.next()) { Mst_userVo userVo = new Mst_userVo(); userVo.setId(resultSet.getInt("id")); userVo.setUsername(resultSet.getString("username")); userVo.setPassword(resultSet.getString("password")); userVo.setLastlogindate(resultSet.getTimestamp("lastlogindate")); userVo.setAdminflag(resultSet.getByte("adminFlag")); session.setAttribute("userVo", userVo); } RequestDispatcher dispatcher = req.getRequestDispatcher("/edituser.jsp"); dispatcher.forward(req, resp); } catch (SQLException e) { // TODO 自動生成された catch ブロック e.printStackTrace(); } } }