I am trying to get a value from the result set and then set that value via reflection on a setMethod in a specific class. I am having an issue when my result set comes back with a smallint column in MSSQL and It trys to convert that smallint to a Integer (this is what my set method requires is an int for that pojo).
ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount();
ArrayList<T> results = new ArrayList<>(rs.getFetchSize());
T obj = klass.newInstance();
CaseInsensitiveMap map = getInsensitiveMethodMap(obj.getClass());
while (rs.next()) {
for (int i = 1; i <= columns; ++i) {
String columnName = SqlValue.SET_LOWER + md.getColumnName(i);
Method m = (Method) map.get(columnName);
// Object test = rs.getObject(i, m.getParameterTypes()[0]);
// System.out.println(columnName + " " + rs.getObject(i));
m.invoke(obj, rs.getObject(i, m.getParameterTypes()[0]));
}
results.add(obj);
obj = klass.newInstance();
}
return results;
As you can see I am trying to use ResultSet.getObject(Integer, Class) which I am getting the class from the method parameter type. Currently I am getting an error saying "java.sql.SQLFeatureNotSupportedException: This operation is not supported." Is there a way to do this? Be able to dynamically get a specified type value from the result set?
Aucun commentaire:
Enregistrer un commentaire