samedi 9 juillet 2016

C3P0 rawStatementOperation cause IllegalArgumentException: object is not an instance of declaring class

My server use hibernate 3.6 and c3p0-0.9.5.2 with a mysql database. I try to use this particular function of mysql jdbc driver

com.mysql.jdbc.Statement.setLocalInfileInputStream(InputStream is)

So as c3p0 document, I need to use rawStatementOperation() function of com.mchange.v2.c3p0.impl.NewProxyStatement:

InputStream is = new ByteArrayInputStream("myString".getBytes());
Method m = com.mysql.jdbc.Statement.class.getMethod("setLocalInfileInputStream", new Class[]{InputStream.class});
NewProxyStatement proxyStatement = (NewProxyStatement) connection.createStatement();
proxyStatement.rawStatementOperation(m, NewProxyStatement.RAW_STATEMENT, new Object[]{is});

It bugs with error :

Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:497)
  at com.mchange.v2.c3p0.impl.NewProxyStatement.rawStatementOperation(NewProxyStatement.java:1077)

It's as if it does not recognize ByteArrayInputStream as a child class of InputStream

I also tried to create Method with ByteArrayInputStream.class instead of InputStream.class, but it does not find the function

NoSuchMethodException: com.mysql.jdbc.Statement.setLocalInfileInputStream(java.io.ByteArrayInputStream)

I've done st wrong? Thanks a lot





Aucun commentaire:

Enregistrer un commentaire