Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i4xN0-0006P5-BR for pgsql-jdbc@arkaria.postgresql.org; Tue, 03 Sep 2019 01:12:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i4xMy-0002wX-Vk for pgsql-jdbc@arkaria.postgresql.org; Tue, 03 Sep 2019 01:12:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i4xMy-0002wL-OZ for pgsql-jdbc@lists.postgresql.org; Tue, 03 Sep 2019 01:12:28 +0000 Received: from mail-io1-xd2a.google.com ([2607:f8b0:4864:20::d2a]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i4xMw-000730-Jv for pgsql-jdbc@lists.postgresql.org; Tue, 03 Sep 2019 01:12:28 +0000 Received: by mail-io1-xd2a.google.com with SMTP id u185so28388686iod.10 for ; Mon, 02 Sep 2019 18:12:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=z4MO5L5z2RqTcrDeNPtUs001XXPHuXm+Yo/lZRuwlPQ=; b=KMMNP8xKl8zX5CPkIBGsszsTfEpHMloVeCT+dkfnpldmH3Jpx1SDgvS8Lij+T0eD9U yasO4SXbcSkqNztJMtG8hJJZijYEEw3aX1D8AyKW9IL/WTkp/vn0A4Yg1pMdmQFE9rPA uBc+oCiri4YpKbpV65SikjLgIH+Bz8kwUmENfnGCyuFkCkLomxcDOZ5h0OUELl+yBQSw gx7Kf8ynHDdEUGPVJaiwapTNDMDI3tphIQQddyR2H9olFeZ0kGBk40o1bkRx90DIhz0j Y0jLcV8Un5cnIzCVUR/IIc+v5j4I1I2xiEOqOkC+jEpinj0+cVCimUM9iZnKXLqZb7RW /I0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=z4MO5L5z2RqTcrDeNPtUs001XXPHuXm+Yo/lZRuwlPQ=; b=kD7h6h8t/9k8pVTqCe0vCU07ea9SuBP9d4nBZlXbZeH8kESNSV3M/Mu7XaY08XqZt+ qGeftpBJBY2hA/glHP6DentUTkb1r5vxIOOmZWl3ZBPNRzHjfJ7moOXpHQ6FYR46vwh6 bMF5r74wvblDZgFZxtV9Ucju81HziFHkVlbPUI3RutR6NkPG3vyMIVmLfHnWx14ZwJmP s7v35OgJbEq6x7QdCmlvmgC+7wwVCcktjpx5rJCvHKpfeZy6nAAtpIfWWaKSIVsqhfSE wVq5HbML9N1azqiuIrPslCfuBGXdY62mVngSs6JUI/71O/xpJEP8fQhoJe2XqFIZ/zCL zRwQ== X-Gm-Message-State: APjAAAXwDWjc8LjV7Nry1IMuABw9NPTp8nENhn6c85yUJ9m6HYuqS5Wy RxlAbMe9XryD9WiVSgsQdW0= X-Google-Smtp-Source: APXvYqw6V1qsAXMsItmPDEofqSQBxsY7EUNdjz2j19FJxPTptRq+ZsHYU5GFXlRw1ZAUeRQ6IDJYnw== X-Received: by 2002:a02:2a0b:: with SMTP id w11mr7527981jaw.43.1567473144949; Mon, 02 Sep 2019 18:12:24 -0700 (PDT) Received: from [192.168.1.108] (c-73-63-59-118.hsd1.ut.comcast.net. [73.63.59.118]) by smtp.gmail.com with ESMTPSA id d20sm10383542ioh.2.2019.09.02.18.12.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Sep 2019 18:12:24 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: how to resolve org.postgresql.util.PSQLException: ResultSet not positioned properly, perhaps you need to call next. From: Rob Sargent In-Reply-To: <932079842.712590.1567405714491@mail.yahoo.com> Date: Mon, 2 Sep 2019 19:12:23 -0600 Cc: pgsql-jdbc@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <58285538-686D-45F6-B5A5-883DBE7D0C10@gmail.com> References: <932079842.712590.1567405714491@mail.yahoo.com> To: Karen Goh X-Mailer: Apple Mail (2.3445.104.11) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Sep 2, 2019, at 12:28 AM, Karen Goh wrote: >=20 > Hi experts, >=20 > I have been trying to find a solution in the internet but there is = only 1 solution offered by stackoverflow in which the user uses if it is = not there then use a else to print out there is no more data/row that = appeared in that column. >=20 > Basically, I was trying to get a List which meet certain = search condition so the data will come from 2 tables - one of which is a = column from a join table and the List falls under this table. >=20 > So, here's the code that I attempt to get the data out but keep = getting ResultSet not positioned properly. >=20 > String[] subjectNames =3D = request.getParameterValues("txtsubjects"); > String zipcode =3D = request.getParameter("location"); > List subjList =3D new = ArrayList(Arrays.asList(subjectNames)); =09 > List myList =3D new ArrayList<>(); > ArrayList subList =3D new ArrayList<>(); > CopyOnWriteArrayListnewSub =3D new = CopyOnWriteArrayList();=20 > tutor t =3D new tutor(); >=20 > =09 > String sql1 =3D "select t.tutor_contact_no, = t.zipcode, t.tutor_id, t2.subject_name FROM s_tutor t JOIN = tutor_subject t2 ON t.tutor_id =3D t2.tutor_id where t.zipcode =3D ? = And t2.subject_name =3D Any((?))"; > =09 > PreparedStatement ps2 =3D = connection.prepareStatement(sql1); > ps2.setString(1, zipcode); > for (int i =3D 0; i < subjectNames.length; i++) = { > Array array =3D = connection.createArrayOf("text", subjList.toArray()); > ps2.setArray(2, array); > } > ResultSet rs =3D ps2.executeQuery(); > while (rs.next()) { =09 > = t.setContactNo(rs.getString("tutor_contact_no")); =09 > t.setZipcode(rs.getString("zipcode")); > t.settutor_id(rs.getInt("tutor_id")); = =09 >=20 > =20 > for (String s: subjList) > if = (s.contains(rs.getString("subject_name"))) Are you sure you want to add to the subList you=E2=80=99re iterating = through? > = subjList.add(rs.getString("subject_name")); > newSub.addAll(subjList); > } > myList.add(t); =09 > request.setAttribute("tutors", myList); = =20 > request.setAttribute("sub", newSub);=09 >=20 > Please. I hope someone can tell me what's wrong with the code or how = to overcome this error...I have been struggling for 2 weeks already. >=20 > Thanks. > } > myList.add(t); =09= > request.setAttribute("tutors", myList); = =20 > request.setAttribute("sub", newSub); >=20 >=20 >=20