最近做了一个小东西,对于接口实现类。发现很多都是一个套路,所以备份下,以后可以经常用到! 这几个是单纯查询的实现类。
2013-08-26 22:13
866 查看
/**
* 收支汇总报表---收入(收支项目和金额)
*/
public List receiptsReportFormsFx1(String time1, String time2) {
// TODO Auto-generated method stub
List list = new ArrayList();
System.out.println("------------------");
//String time1 = 2011-01-1
try{
conn = ConfigUtil.getConnection();//调用configutil()连接oracle数据库
String sql = "select ab_name,ab_money from account_book "+
"where ab_fx=1 and (ab_time between to_Date(?,'yyyy-mm-dd') and to_Date(?,'yyyy-mm-dd'))";
//对数据库信息进行查询
pstmt = conn.prepareStatement(sql);//创建一个 PreparedStatement 对象来将参数化的 SQL 语句发送到数据库。
pstmt.setString(1, time1);
pstmt.setString(2, time2);
pstmt.executeUpdate(); //在此 PreparedStatement 对象中执行 SQL 语句
rs = pstmt.executeQuery();//执行给定的 SQL 语句,该语句返回单个 ResultSet 对象
while(rs.next()){
ReportForm reportform = new ReportForm();
reportform.setAb_name(rs.getString(1));
reportform.setAb_money(rs.getInt(2));
list.add(reportform);//将获得的数据添加到list表中
}
}catch(Exception e){
e.printStackTrace();
}finally{
/**
* 关闭数据连接
*/
ConfigUtil.closeRs(rs);
ConfigUtil.closePstmt(pstmt);
ConfigUtil.closeConn(conn);
}
return list;//返回数据列表
}
/**
* 收支汇总报表---支出(支出项目和金额)
*/
public List receiptsReportFormsFx2(String time1, String time2) {
// TODO Auto-generated method stub
List list = new ArrayList();
try{
conn = ConfigUtil.getConnection();//调用configutil()连接oracle数据库
String sql = "select ab_name,ab_money from account_book "+
"where ab_fx=0 and (ab_time between to_Date(?,'yyyy-mm-dd') and to_Date(?,'yyyy-mm-dd'))";
//对数据库信息进行查询
pstmt = conn.prepareStatement(sql);//创建一个 PreparedStatement 对象来将参数化的 SQL 语句发送到数据库。
pstmt.setString(1,time1);
pstmt.setString(2,time2);
pstmt.executeUpdate(); //在此 PreparedStatement 对象中执行 SQL 语句
rs = pstmt.executeQuery();//执行给定的 SQL 语句,该语句返回单个 ResultSet 对象
while(rs.next()){
ReportForm reportform = new ReportForm();
reportform.setAb_name(rs.getString(1));
reportform.setAb_money(rs.getInt(2));
list.add(reportform);//将获得的数据添加到list表中
}
}catch(Exception e){
e.printStackTrace();
}finally{
/**
* 关闭数据连接
*/
ConfigUtil.closeRs(rs);
ConfigUtil.closePstmt(pstmt);
ConfigUtil.closeConn(conn);
}
return list;//返回数据列表
}
/**
* 年度收支报表统计(支出项目,金额和支出总金额)
*/
public List yearReceiptsReportForms1(String year) {
List list = new ArrayList();
try{
conn = ConfigUtil.getConnection();//调用configutil()连接oracle数据库
String sql =" select ab_name,sum(ab_money) from account_book where to_char(ab_time,'yyyy')=? and ab_fx=0"+
"group by ab_name, to_char(ab_time,'mm')" +
"order by to_char(ab_time,'mm')asc";//对数据库信息进行查询
pstmt = conn.prepareStatement(sql);//创建一个 PreparedStatement 对象来将参数化的 SQL 语句发送到数据库。
pstmt.setString(1, year);
pstmt.executeUpdate();//在此 PreparedStatement 对象中执行 SQL 语句
rs = pstmt.executeQuery();//执行给定的 SQL 语句,该语句返回单个 ResultSet 对象
while(rs.next()){
ReportForm reportform = new ReportForm();
reportform.setAb_name(rs.getString(1));
reportform.setSumab_money(rs.getDouble(2));
list.add(reportform);//将获得的数据添加到list表中
}
}catch(Exception e){
e.printStackTrace();
}finally{
/**
* 关闭数据连接
*/
ConfigUtil.closeRs(rs);
ConfigUtil.closePstmt(pstmt);
ConfigUtil.closeConn(conn);
}
// TODO Auto-generated method stub
return list;//返回数据列表
}
/**
* 年度收支报表统计(收入项目,金额和收入总金额)
*/
public List yearReceiptsReportForms2(String year) {
// TODO Auto-generated method stub
List list = new ArrayList();
try{
conn = ConfigUtil.getConnection();//调用configutil()连接oracle数据库
String sql =" select ab_name,sum(ab_money) from account_book where to_char(ab_time,'yyyy')=? and ab_fx=1"+
"group by ab_name, to_char(ab_time,'mm')" +
"order by to_char(ab_time,'mm')asc";//对数据库信息进行查询
pstmt = conn.prepareStatement(sql);//创建一个 PreparedStatement 对象来将参数化的 SQL 语句发送到数据库。
pstmt.setString(1, year);
pstmt.executeUpdate();//在此 PreparedStatement 对象中执行 SQL 语句
rs = pstmt.executeQuery();//执行给定的 SQL 语句,该语句返回单个 ResultSet 对象
while(rs.next()){
ReportForm reportform = new ReportForm();
reportform.setAb_name(rs.getString(1));
reportform.setSumab_money(rs.getDouble(2));
list.add(reportform);//将获得的数据添加到list表中
}
}catch(Exception e){
e.printStackTrace();
}finally{
/**
* 关闭数据连接
*/
ConfigUtil.closeRs(rs);
ConfigUtil.closePstmt(pstmt);
ConfigUtil.closeConn(conn);
}
// TODO Auto-generated method stub
return list;//返回数据列表
}
* 收支汇总报表---收入(收支项目和金额)
*/
public List receiptsReportFormsFx1(String time1, String time2) {
// TODO Auto-generated method stub
List list = new ArrayList();
System.out.println("------------------");
//String time1 = 2011-01-1
try{
conn = ConfigUtil.getConnection();//调用configutil()连接oracle数据库
String sql = "select ab_name,ab_money from account_book "+
"where ab_fx=1 and (ab_time between to_Date(?,'yyyy-mm-dd') and to_Date(?,'yyyy-mm-dd'))";
//对数据库信息进行查询
pstmt = conn.prepareStatement(sql);//创建一个 PreparedStatement 对象来将参数化的 SQL 语句发送到数据库。
pstmt.setString(1, time1);
pstmt.setString(2, time2);
pstmt.executeUpdate(); //在此 PreparedStatement 对象中执行 SQL 语句
rs = pstmt.executeQuery();//执行给定的 SQL 语句,该语句返回单个 ResultSet 对象
while(rs.next()){
ReportForm reportform = new ReportForm();
reportform.setAb_name(rs.getString(1));
reportform.setAb_money(rs.getInt(2));
list.add(reportform);//将获得的数据添加到list表中
}
}catch(Exception e){
e.printStackTrace();
}finally{
/**
* 关闭数据连接
*/
ConfigUtil.closeRs(rs);
ConfigUtil.closePstmt(pstmt);
ConfigUtil.closeConn(conn);
}
return list;//返回数据列表
}
/**
* 收支汇总报表---支出(支出项目和金额)
*/
public List receiptsReportFormsFx2(String time1, String time2) {
// TODO Auto-generated method stub
List list = new ArrayList();
try{
conn = ConfigUtil.getConnection();//调用configutil()连接oracle数据库
String sql = "select ab_name,ab_money from account_book "+
"where ab_fx=0 and (ab_time between to_Date(?,'yyyy-mm-dd') and to_Date(?,'yyyy-mm-dd'))";
//对数据库信息进行查询
pstmt = conn.prepareStatement(sql);//创建一个 PreparedStatement 对象来将参数化的 SQL 语句发送到数据库。
pstmt.setString(1,time1);
pstmt.setString(2,time2);
pstmt.executeUpdate(); //在此 PreparedStatement 对象中执行 SQL 语句
rs = pstmt.executeQuery();//执行给定的 SQL 语句,该语句返回单个 ResultSet 对象
while(rs.next()){
ReportForm reportform = new ReportForm();
reportform.setAb_name(rs.getString(1));
reportform.setAb_money(rs.getInt(2));
list.add(reportform);//将获得的数据添加到list表中
}
}catch(Exception e){
e.printStackTrace();
}finally{
/**
* 关闭数据连接
*/
ConfigUtil.closeRs(rs);
ConfigUtil.closePstmt(pstmt);
ConfigUtil.closeConn(conn);
}
return list;//返回数据列表
}
/**
* 年度收支报表统计(支出项目,金额和支出总金额)
*/
public List yearReceiptsReportForms1(String year) {
List list = new ArrayList();
try{
conn = ConfigUtil.getConnection();//调用configutil()连接oracle数据库
String sql =" select ab_name,sum(ab_money) from account_book where to_char(ab_time,'yyyy')=? and ab_fx=0"+
"group by ab_name, to_char(ab_time,'mm')" +
"order by to_char(ab_time,'mm')asc";//对数据库信息进行查询
pstmt = conn.prepareStatement(sql);//创建一个 PreparedStatement 对象来将参数化的 SQL 语句发送到数据库。
pstmt.setString(1, year);
pstmt.executeUpdate();//在此 PreparedStatement 对象中执行 SQL 语句
rs = pstmt.executeQuery();//执行给定的 SQL 语句,该语句返回单个 ResultSet 对象
while(rs.next()){
ReportForm reportform = new ReportForm();
reportform.setAb_name(rs.getString(1));
reportform.setSumab_money(rs.getDouble(2));
list.add(reportform);//将获得的数据添加到list表中
}
}catch(Exception e){
e.printStackTrace();
}finally{
/**
* 关闭数据连接
*/
ConfigUtil.closeRs(rs);
ConfigUtil.closePstmt(pstmt);
ConfigUtil.closeConn(conn);
}
// TODO Auto-generated method stub
return list;//返回数据列表
}
/**
* 年度收支报表统计(收入项目,金额和收入总金额)
*/
public List yearReceiptsReportForms2(String year) {
// TODO Auto-generated method stub
List list = new ArrayList();
try{
conn = ConfigUtil.getConnection();//调用configutil()连接oracle数据库
String sql =" select ab_name,sum(ab_money) from account_book where to_char(ab_time,'yyyy')=? and ab_fx=1"+
"group by ab_name, to_char(ab_time,'mm')" +
"order by to_char(ab_time,'mm')asc";//对数据库信息进行查询
pstmt = conn.prepareStatement(sql);//创建一个 PreparedStatement 对象来将参数化的 SQL 语句发送到数据库。
pstmt.setString(1, year);
pstmt.executeUpdate();//在此 PreparedStatement 对象中执行 SQL 语句
rs = pstmt.executeQuery();//执行给定的 SQL 语句,该语句返回单个 ResultSet 对象
while(rs.next()){
ReportForm reportform = new ReportForm();
reportform.setAb_name(rs.getString(1));
reportform.setSumab_money(rs.getDouble(2));
list.add(reportform);//将获得的数据添加到list表中
}
}catch(Exception e){
e.printStackTrace();
}finally{
/**
* 关闭数据连接
*/
ConfigUtil.closeRs(rs);
ConfigUtil.closePstmt(pstmt);
ConfigUtil.closeConn(conn);
}
// TODO Auto-generated method stub
return list;//返回数据列表
}
相关文章推荐
- 最近在写导出excel表格的代码,发现网上大部分代码都是导出简单格式的excel,所以自己顺便就写了一个导出复杂表格的工具类,有些代码是借鉴网友的,同时也谢谢分享代码的朋友们.
- 最近由于要用到分隔条,找到了一篇讲原理的, 实现了一个。可以双击缩到左边,可以左右拖动
- Android上实现一个简单的天气预报APP(十一) Preference存储最近一次查询的城市
- 匿名内部类到底可不可以继承类或实现接口? Interface A{ public void method(); } 这时你可以写一个如下的语句得到接口A的实现类的对象 A a=new
- HTTP协议中的短轮询、长轮询、长连接和短连接 序言 最近刚到公司不到一个月,正处于熟悉项目和源码的阶段,因此最近经常会看一些源码。在研究一个项目的时候,源码里面用到了HTTP的长轮询。由于之前没太
- 最近设计了一个生成asp代码的程序,同时也可以作为数据库管理查询的软件,有兴趣的朋友可以去下载!
- Object-c的类可以多重继承么?可以实现多个接口么?Category是什么?重写一个类的方式用继承好还是分类好?为什么?
- 收藏一个好玩的游戏先,以后可以经常玩
- cassandra——可以预料的查询,如果你的查询条件有一个是根据索引查询,那其它非索引非主键字段,可以通过加一个ALLOW FILTERING来过滤实现
- 今天无意中发现JavaBean类基本都要求实现了Serializable接口,以前只是知道序列化以后,可以通过io流的方式将对象序列化和反序列化,进行存取,但不知道为什么需要序列化,今天总结一下
- 在android开发中,经常用到去解析xml文件,常见的解析xml的方式有一下三种:SAX、Pull、Dom解析方式。最近做了一个android版的CSDN阅读器,用到了其中的两种(sax,pull)
- Effective Java 对于所有对象都通用的方法 12.考虑实现Comparable(可以比较)接口
- 在网上找的一个Flex文件上传代码,记录下来,以后用到的时候可以马上能用:
- 用LinearLayout和RelativeLayout实现精确布局(一个经常用到的布局)
- 简单的socket连接,实现服务端可以获得多个客户端连接(备份,方便以后查询)
- 最近写了一个红包雨的小功能,但感觉自己的js还有很多地方可以提高,望大神们可以帮忙指点一二
- 最近学习希尔排序,发现了新的好玩的!我看网上都是用插入实现的我试着用冒泡实现
- HTML常用的特殊符号总结 2014年9月12日 22704次浏览 html中经常会用到一些特殊符号,例如箭头,雪花,心形等等,这些符号就不用css样式或者图片来写了,直接用html特殊符号可以实现。
- 一个接口Test可以被new吗?new完就可以直接使用Test中的方法了吗(其实Test中的方法在TestIMP中实现)?
- Object-c的类可以多重继承么?可以实现多个接口么?Category是什么?重写一个类的方式用继承好还是分类好?为什么?