Re: Right version of jdbc

From: Raivo Rebane <raivore55(at)gmail(dot)com>
To: postgresql439848(at)heinz-it(dot)de
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Right version of jdbc
Date: 2023-09-30 10:49:29
Message-ID: CAMH5fpviQUcdPF0Twq0K4EvPTxeYgVZz4iW0U7xuJTqZ21SCEw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thanks for very much for help.
It seems that I can do the test project for new job.
In future I use help of chat.gpt

Regards
Raivo

On Sat, Sep 30, 2023 at 11:15 AM <postgresql439848(at)heinz-it(dot)de> wrote:

> 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
>
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dave Cramer 2023-09-30 10:53:05 Re: Right version of jdbc
Previous Message Amn Ojee Uw 2023-09-30 09:58:27 Re: [EXT] YNT: Need help tuning a query