public boolean select(String email) { con = (Connection) DBConnector.getConnection(); try { String sql = "SELECT mail_address FROM user WHERE mail_address = ?"; ps = (PreparedStatement) con.prepareStatement(sql); ps.setString(1, email); ResultSet rs = ps.executeQuery(); if (rs.next()) { rs.getString(1); result = true; } } catch (SQLException e) { e.printStackTrace(); } finally { if (con != null) { try { con.close(); } catch (SQLException e) { e.printStackTrace(); } } } return result; }
/** * ユーザー情報をDBから取得する為のメソッド * * @return boolean 処理の成否 */ public boolean selectToUser(int userId, ModifyInformationDTO dto) { boolean result = false; con = (Connection) DBConnector.getConnection(); String sql = "SELECT * FROM user WHERE user_id = ? "; try { PreparedStatement ps = (PreparedStatement) con.prepareStatement(sql); ps.setInt(1, userId); ResultSet resultSet = ps.executeQuery(); if (resultSet.next()) { dto.setUserName(resultSet.getString("user_name")); dto.setNameKana(resultSet.getString("name_kana")); dto.setPostNumber(resultSet.getString("post_number")); dto.setAddress1(resultSet.getString("street_address1")); dto.setAddress2(resultSet.getString("street_address2")); dto.setAddress3(resultSet.getString("street_address3")); dto.setPhoneNumber(resultSet.getString("phone_number")); dto.setEmail(resultSet.getString("mail_address")); dto.setPassword(resultSet.getString("password")); dto.setCreditNumber(resultSet.getString("credit_number")); dto.setToken(resultSet.getString("token")); dto.setUserId(resultSet.getInt("user_id")); result = true; } } catch (SQLException e) { e.printStackTrace(); } finally { try { con.close(); } catch (SQLException e) { e.printStackTrace(); } } return result; }