javamethod-invocation

how to invoke Result Set method in java?


ResultSet data_result = dao.getDetails();

Method resultset_method;

resultset_method = data_result.getClass().getMethod("getInt", Integer.class);

it is giving error:

java.lang.NoSuchMethodException: org.apache.commons.dbcp.DelegatingResultSet.getInt(java.lang.Integer)

Solution

  • The ResultSet's getInt method has two overloads, one that takes an int for the index and one that takes a String for a column name. You're attempting to retrieve a getInt() method, which indeed does not exist.

    You need to supply the types that the method takes - eg, if you were going by name,

    resultset_method = data_result.getClass().getMethod("getInt", String.class);