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 1i5EP2-0007RK-14 for pgsql-jdbc@arkaria.postgresql.org; Tue, 03 Sep 2019 19:23:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i5EP0-0001ZA-RW for pgsql-jdbc@arkaria.postgresql.org; Tue, 03 Sep 2019 19:23:42 +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 1i5EP0-0001YR-II for pgsql-jdbc@lists.postgresql.org; Tue, 03 Sep 2019 19:23:42 +0000 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i5EOx-0001OA-Sx for pgsql-jdbc@lists.postgresql.org; Tue, 03 Sep 2019 19:23:41 +0000 Received: by mail-pg1-x52e.google.com with SMTP id n4so9714061pgv.2 for ; Tue, 03 Sep 2019 12:23:39 -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=NIT/9H2vwrdft3Y8rrT02D5fbmqzBLAN9LoqpJU9Yvk=; b=KAn0EfwIR7kDyLwJWePWZ7Mji2lFftJ8W9EEfQBUNU+50XMhGXMudCF53sSS90tK9J lzkQIwzOecOztA1DCmdU/Hiw3EpCvqvMrtkX6zBAWrjEQp1jjvKBkkqH62a5+DnKFjYx je7vaXtJZLKwYXB474F8ilF9aObLE0irzOiLIp0Rg3UC2lmCHdLgts284wLIAYnpZTD6 SjZy0erd+eEWws/ok2wAKWFNoHpriztUdSwz85QQDDPqAS+uQYbN/NtTuBiwohBdT/fi 5bz74IDW0utWMgOlWAFHyuwAhoWTXTTyjMhS71n08YCY+111MNt1hs0mJfr6bHos1LDb 2oJg== 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=NIT/9H2vwrdft3Y8rrT02D5fbmqzBLAN9LoqpJU9Yvk=; b=TQzqpa/9yGcXWXPImRJB4+nJdhqTMUi/imYaGH6YIGOW5uEJkB7HDPxMRGbpqjDMEX TFIS5cOJOv9/dDIkHxncXEaf+vRmxefUvdpsyNY+JM7VpAPxv/AvBBMVcjQnChNrdKUv ELiebhUYVR4L4k9wI7gQkFElZs1x0WV83Oa0/BJZS4Yesi7qLbCp/YM2mE5TPfdwMhnR DytiklZOZC8tTzNODNu8MIWcr2HrbrhxHQLowgh4gLc+B8Co6lQdLLAwnzqqWRPysebf sUrb0Wr/3eZbetfMbuL5/eUF8IbKERMflg4a55FscCScd3jMOOjn9bwUf7QKAtsruc1D wJrA== X-Gm-Message-State: APjAAAXhohl6FwbJnRB7GUJxf9xfp56iZ/33xpOBtxJ5rwTRY8kbbV2q 4D14d37eRLFqPVD0GDiTWsA= X-Google-Smtp-Source: APXvYqxwnBRgdUzfMnO45DrS7v0yKewIz7FfMEhQfyY8EsPVGikRhwXMKJVePNht/xjTUo5m/EvQCw== X-Received: by 2002:a62:e205:: with SMTP id a5mr42440362pfi.137.1567538217861; Tue, 03 Sep 2019 12:16:57 -0700 (PDT) Received: from [10.106.130.64] ([155.100.47.0]) by smtp.gmail.com with ESMTPSA id u17sm8501856pfm.153.2019.09.03.12.16.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Sep 2019 12:16:57 -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: <1422030722.958511.1567487705474@mail.yahoo.com> Date: Tue, 3 Sep 2019 13:16:56 -0600 Cc: pgsql-jdbc@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <1ACDE5B3-3F0E-4BF0-8C37-DAD09F35F30C@gmail.com> References: <932079842.712590.1567405714491@mail.yahoo.com> <58285538-686D-45F6-B5A5-883DBE7D0C10@gmail.com> <1422030722.958511.1567487705474@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 Well we=E2=80=99ll need to see the stacktrace from the exception and = proof (line numbers) that the exception is in the code you sent. > On Sep 2, 2019, at 11:15 PM, Karen Goh wrote: >=20 >=20 >=20 > Hi Rob, >=20 > I am still getting the same type of error even if I store it in = another List...=20 >=20 > CopyOnWriteArrayList subList =3D new CopyOnWriteArrayList<>();=20= >=20 > subList.add(rs.getString("subject_name")); // note: using a new List >=20 > Are there anybody experienced Java developer that can help ? >=20 >=20 > On Tuesday, September 3, 2019, 9:12:34 AM GMT+8, Rob Sargent = wrote: >=20 >=20 >=20 >=20 > > On Sep 2, 2019, at 12:28 AM, Karen Goh wrote: > > > > Hi experts, > > > > 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. > > > > 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. > > > > So, here's the code that I attempt to get the data out but keep = getting ResultSet not positioned properly. > > > > String[] subjectNames =3D request.getParameterValues("txtsubjects"); > > String zipcode =3D request.getParameter("location"); > > List subjList =3D new = ArrayList(Arrays.asList(subjectNames));=20 > > List myList =3D new ArrayList<>(); > > ArrayList subList =3D new ArrayList<>(); > > CopyOnWriteArrayListnewSub =3D new = CopyOnWriteArrayList(); > > tutor t =3D new tutor(); > > > >=20 > > 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((?))"; > >=20 > > 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()) {=20 > > t.setContactNo(rs.getString("tutor_contact_no"));=20 > > t.setZipcode(rs.getString("zipcode")); > > t.settutor_id(rs.getInt("tutor_id"));=20 > > > >=20 > > for (String s: subjList) > > if (s.contains(rs.getString("subject_name"))) >=20 > Are you sure you want to add to the subList you=E2=80=99re iterating = through? >=20 > > subjList.add(rs.getString("subject_name")); > > newSub.addAll(subjList); > > } > > myList.add(t);=20 > > request.setAttribute("tutors", myList);=20 > > request.setAttribute("sub", newSub);=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. > > > > Thanks. > > } > > myList.add(t);=20 > > request.setAttribute("tutors", myList);=20 > > request.setAttribute("sub", newSub); > > > > > > >=20 >=20