- Java code
try { System.out.println(columnType.substring(columnType.lastIndexOf(".")+1)); setMethods.get(columnName).invoke( obj, new Object [] { rsCls.getMethod("get"+columnType.substring(columnType.lastIndexOf(".")+1)).invoke( result, new Object [] {columnName} ) } ); } catch (SecurityException e) { System.out.println("对象赋值失败,要取得的方法可能是私有,执行到:" + columnName); e.printStackTrace(); } catch (NoSuchMethodException e) { System.out.println("对象赋值失败,找不到要取得的方法,执行到:" + columnName); e.printStackTrace();
控制台输出错误:
java.lang.NoSuchMethodException: java.sql.ResultSet.getString()
java.lang.String
java.lang.String
java.lang.String
String
对象赋值失败,找不到要取得的方法,执行到:passwd
String
对象赋值失败,找不到要取得的方法,执行到:username
String
对象赋值失败,找不到要取得的方法,执行到:email
at java.lang.Class.getMethod(Unknown Source)
at com.liuwei.tools.test.DBUtil.select(DBUtil.java:180)
at com.liuwei.tools.test.DBUtil.main(DBUtil.java:321)
java.lang.NoSuchMethodException: java.sql.ResultSet.getString()
at java.lang.Class.getMethod(Unknown Source)
at com.liuwei.tools.test.DBUtil.select(DBUtil.java:180)
at com.liuwei.tools.test.DBUtil.main(DBUtil.java:321)
java.lang.NoSuchMethodException: java.sql.ResultSet.getString()
at java.lang.Class.getMethod(Unknown Source)
at com.liuwei.tools.test.DBUtil.select(DBUtil.java:180)
at com.liuwei.tools.test.DBUtil.main(DBUtil.java:321)
------解决方案--------------------------------------------------------
rsCls.getMethod("get"+columnType.substring(columnType.lastIndexOf(".")+1) , String.class)
.invoke(result, new Object [] {columnName})