I need to retrieve the values from a ResultSet
to use them via reflexion to invoke a constructor.
I was trying with Class.cast(Object), but I always get an InvalidCastException
.
This is what I have:
Object[] args = new Object[count];
Class<?>[] arr = co.getParameterTypes();
for(i = 0; i<args.length; i++){
args[i] = arr[i].cast(rs.getObject(i+1));
}
Object t;
try {
t = co.newInstance(args);
} catch (Exception e) {
throw new RuntimeException(e);
}
return (T)t;
co is the constructor, and rs is the ResultSet
I already have.