CreateArrayOf AbstractMethodError

I am trying to insert an array into postgres using java code, but always get this error:

SEVERE [http-nio-8080-exec-2]org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service()
 for servlet [] in context with path [/] threw exception 
[Servlet execution threw an exception] with root cause
 java.lang.AbstractMethodError: 
com.mchange.v2.c3p0.impl.NewProxyConnection.createArrayOf(Ljava/lang/String;[Ljava/lang/Object;)Ljava/sql/Array;

Code used

pst = getConnection().prepareStatement(INSERT_QUERY,PreparedStatement.RETURN_GENERATED_KEYS);
        pst.setString(1, t.getname());
        pst.setString(2, t.getEmail());
        Array itemIds = conn.createArrayOf("bigint", t.getItemIds());
        pst.setArray(3, itemIds);

If I run the function through the main class, it works fine, but after deploying to the tomcat server, the http calls fail with the error above.

  • Used DB - Postgres
  • JDBC driver postgres-9.1-901-1.jdbc4
  • c3p0-0.9.5-pre10
  • cat-8.0.24

According to the research I did, createArrayOf () should work with jdbc4 and c3p0-0.9.5.

Using this works great, but I don't see it as the right approach

        if (conn instanceof C3P0ProxyConnection) {
            C3P0ProxyConnection proxy = (C3P0ProxyConnection) conn;
            try {
             Method m = Connection.class.getMethod("createArrayOf", String.class, Object[].class);
             Object[] args = { "bigint", t.getItemIds() };
             itemIds = (Array) proxy.rawConnectionOperation(m, C3P0ProxyConnection.RAW_CONNECTION, args);
            } catch (IllegalArgumentException e) {
                throw new SQLException(e);
            }
         } else {
                itemIds = conn.createArrayOf("bigint", t.getItemIds());
         }

Need help. Thanks

+5
source share
3 answers

, c3p0 - CLASSPATH. c3p0-0.9.5-pre10.jar c3p0-0.9.5.1.jar Maven Central, com.mchange.v2.c3p0.impl.NewProxyConnection createArrayOf.

% javap -sysinfo -cp ./c3p0-0.9.5.1.jar com.mchange.v2.c3p0.impl.NewProxyConnection
Classfile jar:file:/Users/swaldman/tmp/c3p0jars/c3p0-0.9.5.1.jar!/com/mchange/v2/c3p0/impl/NewProxyConnection.class
  Last modified Jun 16, 2015; size 27098 bytes
  MD5 checksum c1ff36b87219ddc84c92fb6c1445a2d1
  Compiled from "NewProxyConnection.java"
public final class com.mchange.v2.c3p0.impl.NewProxyConnection implements java.sql.Connection,com.mchange.v2.c3p0.C3P0ProxyConnection {
   //...
   public synchronized java.sql.Array createArrayOf(java.lang.String, java.lang.Object[]) throws java.sql.SQLException;
   //...
}

, c3p0-0.9.5.1, .

, c3p0 , INFO , c3p0. :

INFO: Initializing c3p0-0.9.5.1 [built 16-June-2015 00:06:36 -0700; debug? true; trace: 10]

, , -, , , 0.9.1.x 0.9.2.x.

!

+3

, c3p0.

maven, pom

<dependency>
    <groupId>c3p0</groupId>
    <artifactId>c3p0</artifactId>
    <version>0.9.1.2</version>
</dependency>

<dependency>
    <groupId>com.mchange</groupId>
    <artifactId>c3p0</artifactId>
    <version>0.9.5.2</version>
</dependency>

, -.

+1

Updating the dependency to the next solved my problem.

<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
0
source

Source: https://habr.com/ru/post/1608889/


All Articles