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;
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 main class it works fine , but after deploying to tomcat server, http calls fail with above error .
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());
}
Need help . Thanks
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;
//...
}
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.
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]
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.
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With