最近做了一个小东西,对于接口实现类。发现很多都是一个套路,所以备份下,以后可以经常用到! 这几个是单纯查询的实现类。
来源:互联网 发布:java中原生态接口开发 编辑:程序博客网 时间:2024/04/24 18:28
/**
* 收支汇总报表---收入(收支项目和金额)
*/
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;//返回数据列表
}
- 最近做了一个小东西,对于接口实现类。发现很多都是一个套路,所以备份下,以后可以经常用到! 这几个是单纯查询的实现类。
- 最近由于要用到分隔条,找到了一篇讲原理的, 实现了一个。可以双击缩到左边,可以左右拖动
- jQuery实现了一个拖拽小东西的程序
- 简单介绍java Enumeration 很多类都是实现了这个接口的 比如StringTokenizer类 方法很类似
- 一个类实现一个接口,可以重写接口中方法的参数类型吗?
- 做一个对于很多类都能使用的单例模式类
- 单纯md5的一个具体实现
- 收藏一个好玩的游戏先,以后可以经常玩
- 这是一个简单的小东西——用html做Diy书签
- 今天学习的时候偶然发现了一个有趣的题目,可以用编程实现。
- 连接就已经构成一个表了,所以这个表可以有条件查询的
- 最近学习框架做了一个小网站,基本功能都实现了但是分页没办法用框架思想实现,查了资料找到一个不错的,修改了下分享下
- 最近根据别人提示的一个想法,东拼西凑,终于实现了android系统中只能看到自己的系统,我称之为唯一系统。 很多企业做设备或是做产品的或是集成商 其中的一部分设备直接用android智能机。担是又不让
- C#判断一个类实现了一个接口
- 研究了一段时间siverlight,最近需要实现一个动画,此动画是循环滚动的动画
- 最近看到了一个远航财经直播不知道是用什么技术实现的
- 本人学了点Java做了几个设计,所以就把一些经常要用的代码发给你们,都是JDBC连接SQL Server2000的JavaBean,绝对跨平台!
- 最近发现了一个不错的数学与工程类软件 englab
- TQ2440之UART
- C++数组引用
- #pragma once与 #ifndef的区别
- POJ 2192 (DP) 或者 搜索
- KDD-2013概述
- 最近做了一个小东西,对于接口实现类。发现很多都是一个套路,所以备份下,以后可以经常用到! 这几个是单纯查询的实现类。
- 2013暑期第二周周赛大二
- 【Java教程】第一讲 Java语言概述(2)
- b3log StaticResources赏析
- Linux常用服务器
- POJ 1753 Flip Game
- poj2263&zoj1952Heavy Cargo(floyd)
- uva 11796 - Dog Distance
- list_entry()详解