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 1i5QqY-0002Kk-PM for pgsql-jdbc@arkaria.postgresql.org; Wed, 04 Sep 2019 08:40:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i5QqX-0003sF-BH for pgsql-jdbc@arkaria.postgresql.org; Wed, 04 Sep 2019 08:40:57 +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 1i5QqX-0003s8-17 for pgsql-jdbc@lists.postgresql.org; Wed, 04 Sep 2019 08:40:57 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i5QqU-00020p-CI for pgsql-jdbc@lists.postgresql.org; Wed, 04 Sep 2019 08:40:56 +0000 Received: by mail-pl1-x636.google.com with SMTP id gn20so9257070plb.2 for ; Wed, 04 Sep 2019 01:40:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=6vwbVM00qXradhigsWGOcbAbrYSBFWwwi+OBc10pw8Q=; b=cyjH/OjB0jP6GJaO+pJV7cEkbIim51vDmmGrjRVcdeC53dfl6sZXRjr9+rHdWzfXMP NQzP6mMA5F2Pl1tc14ddcnUlHm7W12qSN6BJKI7/9e/aLrXwEXQSDNJnET+Nhi12zS4S +S5cl1nk1u/3GIwwXhPIpPoJU8MSwN+llFxQWTqQ3snHKWJpj5/dfc3j9UzcYKADIpEu kVwMzQzkBeoGi77/XWZMUmvSI4mMRqAtrN91zj7VlZUN/jzH9aHRsHaBlcA/l8dtEBiK iklxFby1xHqp3RM+ZuvTp7rWvch0QCqpPNVNq9bcrNi9sW+aq5zcnCR1S/ACTpmc58cD BLpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=6vwbVM00qXradhigsWGOcbAbrYSBFWwwi+OBc10pw8Q=; b=L/mX0ALE7fwPf1duYUE2kxe9Yabs8pPEGOYeg63yiWWcmMxaJG7bc5Xh1kosbRkrDg dt+aGqxr5ivQdoH1nZUwyuYR7DphDprNrnSxJrroZ0lmCHaR2jNn5TeyVYvycbvwCmhl /IN2dPGzTIQ0AcN8FNhV/7xREUVZ8EIXv39+rOi6BUbUHeh3K+6MSxaNJ+ogqXcl3+i4 6ru9qR3k314p1pTdYL4FPudWrsGVdSxlF73KPmzeoESVrgmio/js/yh7Hdag2AEnbq3P 8F7vvQUTBnwIVamaKQ78Os7pj3DxJGy19nqe6ISYPRmeHjXL4G98LfzE+c7294I3f50C 4rIA== X-Gm-Message-State: APjAAAWCuT6uIIlnEqjBLwDOIAhco4ngOhy5C8mp7vvyjtEQWCvK59Zg VUVx5+NHkWI8+MkiY5GWlBU= X-Google-Smtp-Source: APXvYqxQ4s01kH8nl+HqnyvOcIotT6lt8gM6h27rhlXJVnbVxWDLuJCqgm0aIeBFA3/NTfaoav+UtA== X-Received: by 2002:a17:902:8492:: with SMTP id c18mr40335621plo.279.1567586451508; Wed, 04 Sep 2019 01:40:51 -0700 (PDT) Received: from 192-168-1-100.tpgi.com.au (27-32-252-78.tpgi.com.au. [27.32.252.78]) by smtp.gmail.com with ESMTPSA id o130sm34204920pfg.171.2019.09.04.01.40.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2019 01:40:50 -0700 (PDT) Message-ID: <9b008bfa3107e8a3f7505b6f300237d1e13eff7f.camel@gmail.com> Subject: Re: how to resolve org.postgresql.util.PSQLException: ResultSet not positioned properly, perhaps you need to call next. From: rob stone To: Karen Goh , pgsql-jdbc@lists.postgresql.org, Mark Rotteveel Date: Wed, 04 Sep 2019 18:40:46 +1000 In-Reply-To: <1705600642.1365952.1567582413285@mail.yahoo.com> References: <932079842.712590.1567405714491@mail.yahoo.com> <58285538-686D-45F6-B5A5-883DBE7D0C10@gmail.com> <1422030722.958511.1567487705474@mail.yahoo.com> <1ACDE5B3-3F0E-4BF0-8C37-DAD09F35F30C@gmail.com> <860006402.1322813.1567568281784@mail.yahoo.com> <1829430979.1362196.1567576711470@mail.yahoo.com> <8b79560c-3108-af04-e74f-f4fb55aa0624@lawinegevaar.nl> <1705600642.1365952.1567582413285@mail.yahoo.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.30.5-1.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hello, On Wed, 2019-09-04 at 07:33 +0000, Karen Goh wrote: > Here's the entire code again: > > String[] subjectNames = request.getParameterValues("txtsubjects"); > > > String zipcode = request.getParameter("location"); > > > List subjList = new > ArrayList(Arrays.asList(subjectNames)); > > > List myList = new ArrayList<>(); > > > ArrayList subList = new ArrayList<>(); > > > CopyOnWriteArrayListnewSub = new > CopyOnWriteArrayList(); > > > tutor t = new tutor(); > > > > > > > > > String sql1 = "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 = > t2.tutor_id where t.zipcode = ? And t2.subject_name = Any((?))"; > > > > > > PreparedStatement ps2 = connection.prepareStatement(sql1); > > > ps2.setString(1, zipcode); > > > for (int i = 0; i < subjectNames.length; i++) { > > > Array array = connection.createArrayOf("text", > subjList.toArray()); > > > ps2.setArray(2, array); > > > } > > > ResultSet rs = ps2.executeQuery(); > > > while (rs.next()) { > > > t.setContactNo(rs.getString("tutor_contact_no")); > > > t.setZipcode(rs.getString("zipcode")); > > > t.settutor_id(rs.getInt("tutor_id")); > > >for (String : subjList) > As I said last time, I'm not an "expert". subjectNames is declared as an array. In your "for" loop you will be doing ps2.setArray(2, array); multiple times depending on the number of subjects contained in subjectNames. I suspect the query is failing and as there is no try .. catch block to trap the SQLException, this is not reported back to your code. If you alter the postgresql.conf to log all SQL statements, restart, run your test again, look in the log file, it will show the passed parameter values. You can then verify that that the array passed as the second parameter is correct. HTH, Robert