From: | postgresql439848(at)heinz-it(dot)de |
---|---|
To: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Right version of jdbc |
Date: | 2023-09-30 07:51:47 |
Message-ID: | 3c312fb0-4fbd-490b-9670-47a783fa6cf1@heinz-it.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Am 30.09.23 um 08:33 schrieb Raivo Rebane:
> Hi,
> sometimes I am lucky and don't get the old error, but sometime not.
>
> I tried to use PreparedStatement, but I got error -
> org.postgresql.util.PSQLException: Can't use query methods that take a
> query string on a PreparedStatement.
> at
> org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:145)
> at MushroomAPIs.Clean.deleteAllRecordsFromTable(Clean.java:34)
> and java code is -
>
> String deleteQuery = "DELETE FROM " + tableNam
>
> System.out.println(deleteQuery);
>
> PreparedStatement statement = connection.prepareStatement(deleteQuery);
if your statement is already prepared with query, use
statement.exequte(); or statement.executeQuery() without querystring;
if you have a new statement without query, use execute and such with
query string.
>
> May be it's easy for me to use normal statement ?
>
>
> Raivo
>
>
> On Sat, Sep 30, 2023 at 8:27 AM Raivo Rebane <raivore55(at)gmail(dot)com> wrote:
[snip]
Am 30.09.23 um 09:18 schrieb Raivo Rebane:
> I fix previous error what was my bad knowledge,
> But new error occur which is related to postgres postgis jars.
> If You are kind to answer me more;
>
> Java code is :
>
> public static boolean CheckIsNewInMushrooms(Connection connection, Point
> AddLocation, String AddDescription) {
>
> boolean IsNew = true;
>
>
> try {
>
> String sqlQuery = "SELECT location, description FROM mushrooms";
>
> try (PreparedStatement preparedStatement = connection.prepareStatement(
> sqlQuery)) {
>
> ResultSet resultSet = preparedStatement.executeQuery();
>
>
> while (resultSet.next()) {
>
> Point point = (Point) resultSet.getObject("location");
>
> String description = resultSet.getString("description");
>
>
> if (AddLocation.x == point.x && AddLocation.y == point.y && AddDescription
> .equals(description))
>
> IsNew = false;
>
> }
>
> }
>
> } catch (SQLException e) {
>
> e.printStackTrace();
>
> }
>
>
> return IsNew;
>
> }
>
> and at line
>
> Point point = (Point) resultSet.getObject("location");
>
>
> java.lang.ClassCastException: org.postgresql.util.PGobject cannot be cast
> to org.postgis.Point
> at
> MushroomAPIs.ProcAddMushrooms.CheckIsNewInMushrooms(ProcAddMushrooms.java:45)
> How to get Point from resultset ?
> Is it related to postgis driver ?
try another way to cast to Point.
look for the way over PGgeometry like here
https://postgis.net/docs/manual-3.3/ch07.html#idm3092
>
> Regards
> Raivo
From | Date | Subject | |
---|---|---|---|
Next Message | Raivo Rebane | 2023-09-30 08:10:50 | Re: Right version of jdbc |
Previous Message | Raivo Rebane | 2023-09-30 07:18:59 | Re: Right version of jdbc |