涉及到类发射的问题

elex 2005-03-18 05:26:38
网上的实例代码:
public ArrayList Select(String sql,String className){
ArrayList paraList=new ArrayList();
try{
if (conn == null){
Connection();
}
PreparedStatement stmt = conn.prepareStatement(sql);
ResultSet rs = stmt.executeQuery();
String recordValue="";
Object c1=null;
paraList=new ArrayList();
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
while (rs.next()){
c1=Class.forName(className).newInstance();
for (int i=1; i<=columnCount; i++) {
if(rs.getString(rsmd.getColumnName(i))!=null){
recordValue=rs.getString(rsmd.getColumnName(i));
}else{
recordValue="";
}
Method
m=c1.getClass().getMethod(getSetMethodName(rsmd.getColumnName(i)),
new Class[]{recordValue.getClass()});
m.invoke (c1, new Object[]{recordValue});
}
paraList.add(c1);
}
}catch(SQLException ex){

}catch(ClassNotFoundException e){

}catch(NoSuchMethodException e) {

}catch(InvocationTargetException e){

}catch (IllegalAccessException e){

}catch(InstantiationException e){

} finaly{
closeConnection();
return paraList;
}
}

其中:
getSetMethodName(rsmd.getColumnName(i))方法是哪来的,自定义的?
...全文
96 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
xwei520 2005-03-30
  • 打赏
  • 举报
回复
up
vssivl 2005-03-29
  • 打赏
  • 举报
回复
gz
xwei520 2005-03-29
  • 打赏
  • 举报
回复
关注!~
nickyliuk 2005-03-29
  • 打赏
  • 举报
回复
是要对应的。这样set方法才会找到相对应的属性。
elex 2005-03-29
  • 打赏
  • 举报
回复
up
elex 2005-03-20
  • 打赏
  • 举报
回复
up
elex 2005-03-19
  • 打赏
  • 举报
回复
to eexx(eexx)
这样要求数据库字段名与bean中得属性名要对应了吧
eexx 2005-03-19
  • 打赏
  • 举报
回复
一个把传入的String的首字母toUpperCase,再在前面拼接上set,返回形式如setXxxx的String的方法
taglib 2005-03-19
  • 打赏
  • 举报
回复
做个全局搜寻
huangdeji 2005-03-18
  • 打赏
  • 举报
回复
关注一下

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧