关于 BeanListHandler的用法

来源:互联网 发布:苏州网络品牌营销 编辑:程序博客网 时间:2024/05/16 07:33

 首先定义一个bean 要和数据库里的表的字段的类型对应ShowTestReportBean

在bean里建立set和get方法

然后在数据库里查 该表

方法为:

 public List selectTestRecord(String proudct_brand)
  {
   final String SQL="select test_description,test_according,test_result from test_record where product_brand=?";
  
   Object[] params = new Object[] { proudct_brand };
   BeanListHandler blh = new BeanListHandler(ShowTestReportBean.class,
     ModifiedRowProcesser.instance());
   List testRecordtList = new ArrayList();
   try {
    testRecordtList = (ArrayList) db.query(SQL, params, blh);
   
  } catch (SQLException e) {
   e.printStackTrace();
  }
  
  
   return  testRecordtList;
  
  }

这样查出来的结果就直接以bean的形式 放到了list里

然后在jsp页面进行调用就可以了

jsp页面代码如 下:

调试该连接数据库方法是否好用  <body>
 
<%
        String product_brand="1";
  UserConn db = new UserConn();
  List list = db.selectTestRecord(product_brand);
  for(int i=0; i<list.size(); i++){
    ShowTestReportBean t = (ShowTestReportBean) list.get(i);
    out.print(t.getTestAccording()+"********");
    out.println(t.getTestResult()+"------");
  }
%>

  </body>

嘿嘿终于会用这个 了 - -!

原创粉丝点击