Thread: jdbc problem

jdbc problem

From
Raivo Rebane
Date:

Hi,

I hav postgresql 15 installed in my windows computer.

I have maven java project, wich works temporarly in Eclipse, but mvn install did'nt work.

Now it works, but I have got error -

Exception in thread "main" java.lang.NoSuchMethodError: 'org.postgresql.core.Encoding org.postgresql.core.BaseConnection.getEncoding()'
        at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getString(AbstractJdbc2ResultSet.java:1889)
        at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getTimestamp(AbstractJdbc2ResultSet.java:438)
        at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getTimestamp(AbstractJdbc2ResultSet.java:2406)
        at backendproject.BackendMain.main(BackendMain.java:64)

backendproject.BackendMain.main(BackendMain.java:64) line is following -

Timestamp oldest_timestamp = resultSet.getTimestamp("oldest_timestamp");

Query from Java is following -

String query = "SELECT timestamp AS oldest_timestamp FROM mushrooms";

PreparedStatement statement = connection.prepareStatement(query);

ResultSet resultSet = statement.executeQuery();

And pom.xml contains -

<dependencies>

<dependency>

<groupId>org.postgis</groupId>

<artifactId>postgis-jdbc</artifactId>

<version>1.3.3</version>

</dependency>

<dependency>

<groupId>org.postgresql</groupId>

<artifactId>postgresql</artifactId>

<version>42.2.0</version>

</dependency>

and mvn install gives -

[INFO] --- dependency:3.6.0:copy-dependencies (copy-dependencies) @ backendproject --- [INFO] Copying postgis-jdbc-1.3.3.jar to C:\Users\Raivo\eclipse-workspace\backendproject\target\lib\postgis-jdbc-1.3.3.jar [INFO] Copying postgis-stubs-1.3.3.jar to C:\Users\Raivo\eclipse-workspace\backendproject\target\lib\postgis-stubs-1.3.3.jar [INFO] Copying postgresql-8.3-603.jdbc4.jar to C:\Users\Raivo\eclipse-workspace\backendproject\target\lib\postgresql-8.3-603.jdbc4.jar [INFO] Copying postgresql-42.2.0.jar to C:\Users\Raivo\eclipse-workspace\backendproject\target\lib\postgresql-42.2.0.jar

What is reason of this error and how to resolv it ?

Regards

Raivo

Re: jdbc problem

From
postgresql439848@heinz-it.de
Date:
Am 24.09.23 um 19:33 schrieb Raivo Rebane:
> Hi,
>
> I hav postgresql 15 installed in my windows computer.
>
> I have maven java project, wich works temporarly in Eclipse, but mvn
> install did'nt work.
>
> Now it works, but I have got error -
>
> Exception in thread "main" java.lang.NoSuchMethodError:
> 'org.postgresql.core.Encoding
> org.postgresql.core.BaseConnection.getEncoding()'
>          at
> org.postgresql.jdbc2.AbstractJdbc2ResultSet.getString(AbstractJdbc2ResultSet.java:1889)
>          at
> org.postgresql.jdbc2.AbstractJdbc2ResultSet.getTimestamp(AbstractJdbc2ResultSet.java:438)
>          at
> org.postgresql.jdbc2.AbstractJdbc2ResultSet.getTimestamp(AbstractJdbc2ResultSet.java:2406)
>          at backendproject.BackendMain.main(BackendMain.java:64)
>
> backendproject.BackendMain.main(BackendMain.java:64) line is following -
>
> Timestamp oldest_timestamp = resultSet.getTimestamp("oldest_timestamp");
>
> Query from Java is following -
>
> String query = "SELECT timestamp AS oldest_timestamp FROM mushrooms";
>
> PreparedStatement statement = connection.prepareStatement(query);
>
> ResultSet resultSet = statement.executeQuery();
>
> And pom.xml contains -
>
> <dependencies>
>
> <dependency>
>
> <groupId>org.postgis</groupId>
>
> <artifactId>postgis-jdbc</artifactId>
>
> <version>1.3.3</version>
>
> </dependency>
>
> <dependency>
>
> <groupId>org.postgresql</groupId>
>
> <artifactId>postgresql</artifactId>
>
> <version>42.2.0</version>
>
> </dependency>
>
> and mvn install gives -
>
> [INFO] --- dependency:3.6.0:copy-dependencies (copy-dependencies) @
> backendproject --- [INFO] Copying postgis-jdbc-1.3.3.jar to
> C:\Users\Raivo\eclipse-workspace\backendproject\target\lib\postgis-jdbc-1.3.3.jar
> [INFO] Copying postgis-stubs-1.3.3.jar to
> C:\Users\Raivo\eclipse-workspace\backendproject\target\lib\postgis-stubs-1.3.3.jar
> [INFO] Copying postgresql-8.3-603.jdbc4.jar to
> C:\Users\Raivo\eclipse-workspace\backendproject\target\lib\postgresql-8.3-603.jdbc4.jar
> [INFO] Copying postgresql-42.2.0.jar to
> C:\Users\Raivo\eclipse-workspace\backendproject\target\lib\postgresql-42.2.0.jar
>
> What is reason of this error and how to resolv it ?
>
> Regards
>
> Raivo
>
i would try to reorder the maven dependencies, so postgresql part is 
loaded first.

or like other people with same error, try exclude postgis-stubs from 
postgis-jdbc:

|<dependency>
||<groupId>org.postgis</groupId>
||<artifactId>postgis-jdbc</artifactId>
||<version>1.3.3</version>
||<scope>compile</scope>
||<exclusions>
||<exclusion>
||<groupId>org.postgis</groupId>
||<artifactId>postgis-stubs</artifactId>
||</exclusion>
||</exclusions>
||</dependency>|



Re: jdbc problem

From
Laurenz Albe
Date:
On Sun, 2023-09-24 at 20:33 +0300, Raivo Rebane wrote:
> I hav postgresql 15 installed in my windows computer.
>
> I have maven java project, wich works temporarly in Eclipse, but mvn install did'nt work.
>
> Now it works, but I have got error -
>
> Exception in thread "main" java.lang.NoSuchMethodError: 'org.postgresql.core.Encoding
org.postgresql.core.BaseConnection.getEncoding()'
>          at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getString(AbstractJdbc2ResultSet.java:1889)
>          at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getTimestamp(AbstractJdbc2ResultSet.java:438)
>          at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getTimestamp(AbstractJdbc2ResultSet.java:2406)
>          at backendproject.BackendMain.main(BackendMain.java:64)
>
> backendproject.BackendMain.main(BackendMain.java:64) line is following -
>
> Timestamp oldest_timestamp = resultSet.getTimestamp("oldest_timestamp");
>
> Query from Java is following -
>
>             String query = "SELECT timestamp AS oldest_timestamp FROM mushrooms";
>             PreparedStatement statement = connection.prepareStatement(query);
>             ResultSet resultSet = statement.executeQuery();

You should ask the JDBC driver mailing list.

As a first measure, try upgrading to 42.6.0 and see if the error persists.

Yours,
Laurenz Albe