Re: Right version of jdbc

From: Raivo Rebane <raivore55(at)gmail(dot)com>
To: Dave Cramer <davecramer(at)postgres(dot)rocks>
Cc: postgresql439848(at)heinz-it(dot)de, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Right version of jdbc
Date: 2023-09-30 11:51:53
Message-ID: CAMH5fpsknxh4CfqzKmh7QipLc5GKB9ZGoAsR_XmgTWuMVUxP=g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have put it to github in the old place -
https://github.com/raaivore/APIexperiment.git

Raivo

On Sat, Sep 30, 2023 at 1:53 PM Dave Cramer <davecramer(at)postgres(dot)rocks>
wrote:

> Again, can you please post the solution so others can learn as well ?
>
> Dave Cramer
> www.postgres.rocks
>
>
> On Sat, 30 Sept 2023 at 06:49, Raivo Rebane <raivore55(at)gmail(dot)com> wrote:
>
>> 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

Browse pgsql-general by date

  From Date Subject
Next Message pf 2023-09-30 14:01:32 Re: cache lookup failed for function 0
Previous Message Dave Cramer 2023-09-30 10:53:05 Re: Right version of jdbc