小编uma*_*ang的帖子

createArrayOf AbstractMethodError

我正在尝试使用java代码将数组插入到postgres中,但是我总是会收到此错误:

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;
Run Code Online (Sandbox Code Playgroud)

使用的代码

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);
Run Code Online (Sandbox Code Playgroud)

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

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

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

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

        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 …
Run Code Online (Sandbox Code Playgroud)

jdbc c3p0

5
推荐指数
1
解决办法
4561
查看次数

标签 统计

c3p0 ×1

jdbc ×1