mardi 6 mars 2018

Java Reflection - Method not found

I am trying to find the method of a PreparedStatement (ps):

Method method = ps.getClass().getMethod("setLong", int.class, Class.forName("java.lang.Long"));
method.setAccessible(true);
method.invoke(ps, fieldIndex, value);

but it isn't found. I have to use Class.forName("java.lang.Long") instead of Long.class.

For String it works:

Method method = ps.getClass().getMethod("setString", int.class, Class.forName("java.lang.String"));
method.setAccessible(true);
method.invoke(ps, fieldIndex, value);

What am I doing wrong? Any idea? Is the namespace of Long wrong?





Aucun commentaire:

Enregistrer un commentaire