Re: Right version of jdbc

Поиск
Список
Период
Сортировка
От Raivo Rebane
Тема Re: Right version of jdbc
Дата
Msg-id CAMH5fpviQUcdPF0Twq0K4EvPTxeYgVZz4iW0U7xuJTqZ21SCEw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Right version of jdbc  (postgresql439848@heinz-it.de)
Ответы Re: Right version of jdbc  (Dave Cramer <davecramer@postgres.rocks>)
Список 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@heinz-it.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@gmail.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


В списке pgsql-general по дате отправления:

Предыдущее
От: Amn Ojee Uw
Дата:
Сообщение: Re: [EXT] YNT: Need help tuning a query
Следующее
От: Dave Cramer
Дата:
Сообщение: Re: Right version of jdbc