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 1i4gs6-0003b3-Qs for pgsql-jdbc@arkaria.postgresql.org; Mon, 02 Sep 2019 07:35: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 1i4gs5-0000z4-E6 for pgsql-jdbc@arkaria.postgresql.org; Mon, 02 Sep 2019 07:35:29 +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 1i4gs5-0000yl-4G for pgsql-jdbc@lists.postgresql.org; Mon, 02 Sep 2019 07:35:29 +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 1i4gry-0003Mg-Om for pgsql-jdbc@lists.postgresql.org; Mon, 02 Sep 2019 07:35:28 +0000 Received: by mail-pg1-x52e.google.com with SMTP id m3so7020474pgv.13 for ; Mon, 02 Sep 2019 00:35:22 -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=/LU7KWfylulHXbgpugLNOrS7Kf0gKkMNcRm+RVE+azs=; b=Ijlaw2RnOVvAibrcuN8OHRsjSkJnPrF2DuXu8nnacsrhX6tFG6efDizsMVXnfbwZsj HxOKwDW85R/0g0c4hYDFh10wpt/lb+geF2XfYrUigyBigSX3GACzdOmBGBNDJFLya5wH rLanvaKKvvdNsp7E2TE2vbjtNtmU50SP3PvYUhbdHwcmOpppms0mN2dgVagCPH7RSbMH xpCfOdrZBwcUmDRk8pGg+aRKaa6ZXYBo4ik10KrAw553NdcZBMj1tiRM9XA2BTUsrR9W biYNhwurqUnPKgEmN6w63RJEYhwV1/uEgGCw6Arqjo1AfHwi0wTP3t8a07G9lI0Il1c6 QgqQ== 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=/LU7KWfylulHXbgpugLNOrS7Kf0gKkMNcRm+RVE+azs=; b=a4Xb7dMr6MkQb9R1Sdh3Qbm/UCy6uPFv84GFWx7QS9VCr1co9dSgESQMkhP5pzSgM2 9EymHlnYG33gvR4PCf6mXuWIf1BLul5aqB5Dp8IYhgzrw9sgw+rTArMXwfcWy4U7lg6z IisnbeBvGSSiLMHyfF3pTIW7qz1mdTqxyUCxA8mLhYY9vLIhxAVv6IgzFJjNhXZ0VFy9 KbApWgRSmGKK2+jHov88NlcIDzVylQPptC17a7USeBp0NDcr2Ye3gxCV73x02XVQQjt9 4xZZ8dgxnu6Z47MAN9LbFI683/lqz5VCt3JS1JAAlzSztx3iz3n7MHefkUGqJnpT3EQA 5Uhw== X-Gm-Message-State: APjAAAVWodzCrYOsb3KOci2YCViH2jKeosE7j99TSZnP+mPYi99I0FPq nWWJ9zvrrHY6WsO++Q+JLu8= X-Google-Smtp-Source: APXvYqwdAs7D0dL/gt5zYR7LCRUDsuhs6duNTkvtzMmW74+UdOFuttwUAoamC3qEr+OZZ7HwQMQBmA== X-Received: by 2002:a63:2744:: with SMTP id n65mr23863151pgn.277.1567409719981; Mon, 02 Sep 2019 00:35:19 -0700 (PDT) Received: from 192-168-1-100.tpgi.com.au ([210.185.72.17]) by smtp.gmail.com with ESMTPSA id k31sm1106826pjb.14.2019.09.02.00.35.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2019 00:35:19 -0700 (PDT) Message-ID: <20ca43cc21f85a4d8192b0c552011b3478a256ba.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 Date: Mon, 02 Sep 2019 17:35:15 +1000 In-Reply-To: <932079842.712590.1567405714491@mail.yahoo.com> References: <932079842.712590.1567405714491@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 Mon, 2019-09-02 at 06:28 +0000, 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 = > 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_cont > act_no")); > t.setZipcode(rs.getString("zipcode")); > t.settutor_id(rs.getInt("tutor_id")); > > > > for (String s: subjList) > if > (s.contains(rs.getString("subject_name"))) > subjList.add(rs.getString("subject_na > me")); > newSub.addAll(subjList); > } > myList.add(t); > request.setAttribute("tutors", myList); > > request.setAttribute("sub", newSub); > > 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); > > request.setAttribute("tutors", myList); > > request.setAttribute("sub", newSub); > > > I'm not an "expert". It is customary on these lists to supply the Postgres version, O/S, JDBC driver version and the JDK version. Also the error message from the PostgreSql log file. Is t.zipcode defined as INTEGER or VARCHAR? I would have used:- AND T2.subject_name = ANY(string_to_array(?)) supplying a suitably constructed string as the second parameter. You also need to cater for the query returning no rows. HTH, Robert