コード例 #1
0
ファイル: Utils.java プロジェクト: wbotelhos/jintegrity
  public static List<User> loadAllUsers(DbUnitManager dbUnitManager) throws SQLException {
    Connection conn = dbUnitManager.getConnection();
    PreparedStatement ps = conn.prepareStatement("SELECT id, email, name FROM User");
    List<User> userList = new ArrayList<User>();

    try {
      ResultSet rs = ps.executeQuery();

      while (rs.next()) {
        userList.add(new User(rs.getLong("id"), rs.getString("email"), rs.getString("name")));
      }
    } finally {
      conn.close();
      ps.close();
    }

    return userList;
  }
コード例 #2
0
ファイル: Utils.java プロジェクト: wbotelhos/jintegrity
  public static List<Contact> loadAllContacts(DbUnitManager dbUnitManager) throws SQLException {
    Connection conn = dbUnitManager.getConnection();
    PreparedStatement ps = conn.prepareStatement("SELECT id, phone, user_id FROM Contact");
    List<Contact> contactList = new ArrayList<Contact>();

    try {
      ResultSet rs = ps.executeQuery();

      while (rs.next()) {
        Long userId = rs.getLong("user_id");

        if (userId == null || userId.intValue() == 0) {
          contactList.add(new Contact(rs.getLong("id"), rs.getString("phone")));
        } else {
          contactList.add(new Contact(rs.getLong("id"), rs.getString("phone"), userId));
        }
      }
    } finally {
      conn.close();
      ps.close();
    }

    return contactList;
  }