createArrayOf AbstractMethodError [英] createArrayOf AbstractMethodError

查看:107
本文介绍了createArrayOf AbstractMethodError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Java代码向Postgres插入数组,但是我总是会收到此错误:

I am trying to insert an array to postgres using java code , but I 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;

使用的代码

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

如果我通过主类运行该函数,则可以正常工作,但是在部署到tomcat服务器后,http调用将失败,并出现上述错误.

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

  • 使用的数据库-Postgres
  • JDBC驱动程序postgres-9.1-901-1.jdbc4
  • c3p0-0.9.5-pre10
  • tomcat-8.0.24

根据我所做的研究,createArrayOf()应该与jdbc4和c3p0-0.9.5一起使用.

As per research I have done , createArrayOf() supposed to work with jdbc4 and c3p0-0.9.5 .

使用此方法效果很好,但我认为它不是正确的方法

Using this works fine , but I don't see it as 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());
         }

需要帮助. 谢谢

推荐答案

我强烈怀疑您的应用程序有效CLASSPATH中某处具有较旧的c3p0版本.我已经从Maven Central的c3p0-0.9.5-pre10.jar和c3p0-0.9.5.1.jar下载并验证了com.mchange.v2.c3p0.impl.NewProxyConnection实际上包含了createArrayOf方法.

I strongly suspect that you have an older version of c3p0 somewhere in your application's effective CLASSPATH. I've downloaded and verified from c3p0-0.9.5-pre10.jar and c3p0-0.9.5.1.jar on Maven Central that com.mchange.v2.c3p0.impl.NewProxyConnection does in fact contain the createArrayOf method.

% 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,而不要使用预发行版本.

Although this is not likely the cause of your problem, I recommend that you do upgrade to c3p0-0.9.5.1 rather than using the prerelease version.

要查看您的应用程序实际使用的c3p0版本,请在日志文件中查看INFO,以获取初始化c3p0库时打印的标语.它应该看起来像这样:

To see what version of c3p0 your application is actually using, look at INFO in your log files for the banner printed when the c3p0 library is initialized. It should look something like this:

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版本的库.

I suspect that you will see an older version, that somewhere, perhaps among the transitive dependencies, you are pulling in 0.9.1.x or 0.9.2.x versions of the library.

祝你好运!

这篇关于createArrayOf AbstractMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆