package pers.gulo.fm.dao.impl;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.sql.DataSource;
import org.apache.commons.dbutils.QueryRunner;
import pers.gulo.fm.dao.AdminDao;
import pers.gulo.fm.dao.resultSetHandler.AirPlaneResultSetHandler;
import pers.gulo.fm.dao.resultSetHandler.CountResultSetHandler;
import pers.gulo.fm.dao.resultSetHandler.FlightResultSetHandler;
import pers.gulo.fm.dao.resultSetHandler.FloatResultSetHandler;
import pers.gulo.fm.dao.resultSetHandler.OrderResultSetHandler;
import pers.gulo.fm.dao.resultSetHandler.UserResultSetHandler;
import pers.gulo.fm.domain.AirPlane;
import pers.gulo.fm.domain.Flight;
import pers.gulo.fm.domain.Order;
import pers.gulo.fm.domain.Statistic;
import pers.gulo.fm.domain.User;
import pers.gulo.fm.exception.FMException;
import pers.gulo.fm.utils.DaoUtils;
public class AdminDaoImpl implements AdminDao{
private static final String INSERT_AIRPLANE_SQL="insert into T_AIRPLANE values (null,?,?)";
private static final String DELETE_AIRPLANE_SQL="delete from T_AIRPLANE where A_NO=?";
private static final String INSERT_FLIGHT_SQL="insert into T_FLIGHT values(null,?,?,?,?,?,0)";
private static final String UPDATE_FLIGHT_SQL="update T_FLIGHT set F_A_NO=?,F_START=?,F_DIST=?,F_PRICE=?,F_TIME=? where F_NO = ?";
private static final String QUERY_USERS="select * from T_USER";
private static final String DELETE_FLIGHT="delete from T_FLIGHT where F_NO = ?";
private static final String QUERY_ALL_FLIGHT="select * from T_FLIGHT f,T_AIRPLANE a where a.A_NO=f.F_A_NO";
private static final String QUERY_ALL_AIRPLANE="select * from T_AIRPLANE";
private static final String DELETE_USER_SQL="delete from T_USER where U_NO=?";
private static final String UPDATE_USER_SQL="update T_USER set U_NICKNAME=? ,U_ID=? where U_NO =?";
private static final String QUERY_ALL_ORDER="select * from T_ORDER o,T_USER u,T_FLIGHT f,T_AIRPLANE a where o.O_U_NO=u.U_NO and o.O_F_NO=f.F_NO and f.F_A_NO=a.A_NO";
private static final String QUERY_FLIGHT_NUM_WEEK_SQL="select count(*) from T_FLIGHT where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(F_TIME)";
private static final String QUERY_FLIGHT_NUM_MONTH_SQL="select count(*) from T_FLIGHT where DATE_SUB(CURDATE(), INTERVAL 1 MONTH) <= date(F_TIME)";
private static final String QUERY_FLIGHT_NUM_SQL="select count(*) from T_FLIGHT";
private static final String QUERY_ORDER_NUM_WEEK_SQL="select count(*) from T_ORDER where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(O_TIME)";
private static final String QUERY_ORDER_NUM_MONTH_SQL="select count(*) from T_ORDER where DATE_SUB(CURDATE(), INTERVAL 1 MONTH) <= date(O_TIME)";
private static final String QUERY_ORDER_NUM_SQL="select count(*) from T_ORDER";
private static final String QUERY_INCOME_WEEK_SQL="select sum(F_PRICE) from T_ORDER o,T_FLIGHT f where o.O_F_NO=f.F_NO and O_IS_PAYED=1 and O_IS_CANCELED=0 and DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(O_TIME)";
private static final String QUERY_INCOME_MONTH_SQL="select sum(F_PRICE) from T_ORDER o,T_FLIGHT f where o.O_F_NO=f.F_NO and O_IS_PAYED=1 and O_IS_CANCELED=0 and DATE_SUB(CURDATE(), INTERVAL 1 MONTH) <= date(O_TIME)";
private static final String QUERY_INCOME_SQL="select sum(F_PRICE) from T_ORDER o,T_FLIGHT f where o.O_F_NO=f.F_NO and O_IS_PAYED=1 and O_IS_CANCELED=0";
@Override
public void insertAirPlane(AirPlane airPlane) throws FMException {
QueryRunner runner= new QueryRunner(DaoUtils.getSource());
try {
runner.update(INSERT_AIRPLANE_SQL, airPlane.getModel(),airPlane.getCapacity());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new FMException("插入信息失败!");
}
}
@Override
public void deleteAirPlane(AirPlane airPlane) throws FMException{
QueryRunner runner= new QueryRunner(DaoUtils.getSource());
try {
runner.update(DELETE_AIRPLANE_SQL,airPlane.getNo());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new FMException("外键约束!删除班机失败!");
}
}
@Override
public void insertFlight(Flight flight) throws FMException{
QueryRunner runner= new QueryRunner(DaoUtils.getSource());
try {
runner.update(INSERT_FLIGHT_SQL, flight.getAirPlane().getNo(),flight.getStart(),flight.getDist(),flight.getPrice(),flight.getTime());
System.out.println(flight);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new FMException("添加航班失败! 没有该班机!");
}
}
@Override
public void updateFlight(Flight flight) throws FMException{
QueryRunner runner =new QueryRunner(DaoUtils.getSource());
try {
runner.update(UPDATE_FLIGHT_SQL,flight.getAirPlane().getNo(),flight.getStart(),flight.getDist(),flight.getPrice(),flight.getTime(),flight.getNo());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new FMException("修改航班信息失败!");
}
}
@Override
public List<User> queryUsers() {
List<User> users =null;
QueryRunner runner= new QueryRunner(DaoUtils.getSource());
try {
users= runner.query(QUERY_USERS, new UserResultSetHandler());
} catch (SQLException e) {
e.printStackTrace();
}
return users;
}
@Override
public void deleteFlight(Flight flight) throws FMException {
QueryRunner runner=new QueryRunner(DaoUtils.getSource());
try {
runner.update(DELETE_FLIGHT,flight.getNo());
} catch (SQLException e) {
e.printStackTrace();
throw new FMException("外键约束,不能删除");
}
}
@Override
public List<Flight> queryAllFlight() {
List<Flight> flights=null;
QueryRunner runner=new QueryRunner(DaoUtils.getSource());
try {
flights=runner.query(QUERY_ALL_FLIGHT, new FlightResultSetHandler());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return flights;
}
@Override
public List<AirPlane> queryAllAirPlane() {
List<AirPlane> airPlanes=null;
QueryRunner runner =new QueryRunner(DaoUtils.getSource());
try {
airPlanes = runner.query(QUERY_ALL_AIRPLANE, new AirPlaneResultSetHandler());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return airPlanes;
}
@Override
public void deleteUser(User user) throws FMException {
QueryRunner runner= new QueryRunner(DaoUtils.getSource());
try {
runner.update(DELETE_USER_SQL,user.getNo());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new FMException("由于外键约束,删除失败!");
}
}
@Override
public void updateUser(User user) throws FMException {
QueryRunner runner= new QueryRunner(DaoUtils.getSource());
try {
runner.update(UPDATE_USER_SQL,user.getNickname(),user.getID(),user.getNo());
} catch (SQLException e) {
e.printStackTrace();
throw new FMException("修改用户信息失败!");
}
}
@Override
public List<Order> queryAllOrder() {
List<Order> orderList=null;
QueryRunner runner=new QueryRunner(DaoUtils.getSource());
try {
orderList = runner.query(QUERY_ALL_ORDER, new OrderResultSetHandler());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return orderList;
}
@Override
public Statistic makeStatistic() {
Statistic statistic=new Statistic();
QueryRunner runner= new QueryRunner(DaoUtils.getSource());
try {
statistic.setWeekFlight(runner.query(QUERY_FLIGHT_NUM_WEEK_SQL, new CountResultSetHandler()));
statistic.setMonthFlight(runner.query(QUERY_FLIGHT_NUM_MONTH_SQL, new CountResultSetHandler()));
statistic.setTotalFlight(runner.query(QUERY_FLIGHT_NUM_SQL, new CountResultSetHandler()));
statistic.setWeekOrder(runner.query(QUERY_ORDER_NUM_WEEK_SQL, new CountResultSetHandler()));
statistic.setMonthOrder(runner.query(QUERY_ORDER
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【项目资源】: 包含前端、后端、移动开发、操作系统、人工智能、物联网、信息化管理、数据库、硬件开发、大数据、课程资源、音视频、网站开发等各种技术项目的源码。 包括STM32、ESP8266、PHP、QT、Linux、iOS、C++、Java、python、web、C#、EDA、proteus、RTOS等项目的源码。 【项目质量】: 所有源码都经过严格测试,可以直接运行。 功能在确认正常工作后才上传。 【适用人群】: 适用于希望学习不同技术领域的小白或进阶学习者。 可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。 【附加价值】: 项目具有较高的学习借鉴价值,也可直接拿来修改复刻。 对于有一定基础或热衷于研究的人来说,可以在这些基础代码上进行修改和扩展,实现其他功能。 【沟通交流】: 有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 鼓励下载和使用,并欢迎大家互相学习,共同进步。
资源推荐
资源详情
资源评论
收起资源包目录
数据库课程设计——机票预订系统 JSP+MySQL.zip (155个子文件)
AdminDaoImpl.class 8KB
PassengerDaoImpl.class 8KB
OrderResultSetHandler.class 3KB
AddFlightServlet.class 3KB
UpdateFlightServlet.class 3KB
AdminServiceImpl.class 3KB
CancelServlet.class 3KB
PayServlet.class 3KB
UserDaoImpl.class 3KB
Statistic.class 3KB
AddAirPlaneServlet.class 3KB
BookServlet.class 3KB
AddUserServlet.class 2KB
UpdateUserServlet.class 2KB
Flight.class 2KB
DeleteAirPlaneServlet.class 2KB
DeleteFlightServlet.class 2KB
LoginServlet.class 2KB
JDBCUtils.class 2KB
RechargeServlet.class 2KB
FlightResultSetHandler.class 2KB
Order.class 2KB
User.class 2KB
UserResultSetHandler.class 2KB
AirPlaneResultSetHandler.class 2KB
LogoutServlet.class 1KB
AirPlane.class 1KB
PassengerServiceImpl.class 1KB
UserServiceImpl.class 1KB
FloatResultSetHandler.class 1KB
PassengerDao.class 992B
CountResultSetHandler.class 989B
AdminService.class 929B
AdminDao.class 925B
DaoUtils.class 921B
Main.class 835B
PassengerService.class 423B
UserService.class 372B
FMException.class 367B
UserDao.class 363B
.classpath 1KB
org.eclipse.wst.common.component 502B
org.eclipse.wst.jsdt.ui.superType.container 49B
bootstrap.css 144KB
bootstrap.min.css 120KB
bootstrap.min.css 120KB
bootstrap-theme.css 26KB
bootstrap-theme.min.css 23KB
dashboard.css 2KB
signin.css 793B
glyphicons-halflings-regular.eot 20KB
Dashboard Template for Bootstrap.html 9KB
manage.html 8KB
userInfo.html 2KB
mysql-connector-java-5.1.39-bin.jar 966KB
c3p0-0.9.1.2.jar 596KB
mail.jar 483KB
standard.jar 384KB
commons-beanutils-1.8.3.jar 227KB
commons-io-1.4.jar 106KB
commons-logging-1.1.1.jar 59KB
commons-fileupload-1.2.1.jar 56KB
activation.jar 55KB
commons-dbutils-1.4.jar 48KB
AdminDaoImpl.java 8KB
PassengerDaoImpl.java 7KB
AdminServiceImpl.java 2KB
UserDaoImpl.java 2KB
Statistic.java 2KB
UpdateFlightServlet.java 2KB
OrderResultSetHandler.java 2KB
AddFlightServlet.java 2KB
CancelServlet.java 1KB
LoginServlet.java 1KB
AddUserServlet.java 1KB
AddAirPlaneServlet.java 1KB
PayServlet.java 1KB
UpdateUserServlet.java 1KB
AdminDao.java 1KB
BookServlet.java 1KB
Flight.java 1KB
JDBCUtils.java 1KB
PassengerDao.java 1KB
DeleteAirPlaneServlet.java 1KB
RechargeServlet.java 1KB
User.java 1KB
DeleteFlightServlet.java 1KB
Main.java 1KB
Order.java 1KB
FlightResultSetHandler.java 1KB
AdminService.java 940B
UserResultSetHandler.java 833B
LogoutServlet.java 806B
PassengerServiceImpl.java 791B
AirPlaneResultSetHandler.java 711B
UserServiceImpl.java 690B
AirPlane.java 625B
UserDao.java 548B
PassengerService.java 544B
DaoUtils.java 522B
共 155 条
- 1
- 2
资源评论
妄北y
- 粉丝: 1w+
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功