时间:2021-07-01 10:21:17 帮助过:17人阅读
定义两个变量,sDate是起始查询,bDate是截止查询
Dao dao = new Dao(); List<record> sList = dao.name(sDate,bDate);
调用的方法具体内容为
public List<record> name(java.sql.Date sDate , java.sql.Date pDate) { String sql = "select * from record where date BETWEEN ‘"+sDate+"‘ and ‘ "+pDate+"‘"; System.out.println(sql); Connection conn =Dao.getconn(); List<record> list=new ArrayList<record>(); try { PreparedStatement pst=conn.prepareStatement(sql); ResultSet rst=pst.executeQuery(); while(rst.next()) { record r=new record();//此处需要注意不能放在while的外面,否则会导致只有最后一条数据 r.setId(rst.getInt("id")); r.setDate(rst.getDate("date")); r.setMoney(rst.getString("money")); r.setFenlei(rst.getString("fenlei")); r.setBeizhu(rst.getString("beizhu")); list.add(r); } } catch (Exception e) { e.printStackTrace(); } return list; }
Web版记账本开发记录(二)开发过程遇到的问题小结1 对数据库的区间查询
标签:com name ima getc string rac array 图片 new