package com.meession.am.dao.impl;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import com.meession.am.dao.RouteDAO;
import com.meession.am.entity.Route;
public class RouteImpl implements RouteDAO {
private Connection conn = null;
public RouteImpl(Connection conn) {
this.conn = conn;
}
public boolean doCreateRoute(Route route) throws Exception { // 车次信息
boolean flag = false;
String sql = "INSERT INTO Route(name,trainType,fromStation,toStation,departureTime,arrivalTime,businessSeatCount,bPrice,specialSeatCount,spPrice,softSeatCount,sfPrice,hardSeatCount,hPrice,noSeatCount,nPrice,remark,fromStationId,toStationId) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? , ? , ? , ? , ? , ? , ?,(select id from Station where name = ?),(select id from Station where name = ? ))";
PreparedStatement pstmt = null;
try {
pstmt = this.conn.prepareStatement(sql);
pstmt.setString(1, route.getName());
pstmt.setString(2, route.getType());
pstmt.setString(3, route.getFromStation());
pstmt.setString(4, route.getToStation());
pstmt.setTimestamp(5, new java.sql.Timestamp(route.getDepartureTime().getTime()));
pstmt.setTimestamp(6, new java.sql.Timestamp(route.getArrivalTime().getTime()));
pstmt.setInt(7, route.getBusinessSeatCount());
pstmt.setInt(8, route.getbPrice());
pstmt.setInt(9,route.getSpecialSeatCount());
pstmt.setInt(10, route.getSpPrice());
pstmt.setInt(11, route.getSoftSeatCount());
pstmt.setInt(12, route.getSfPrice());
pstmt.setInt(13, route.getHardSeatCount());
pstmt.setInt(14, route.gethPrice());
pstmt.setInt(15, route.getNoSeatCount());
pstmt.setInt(16, route.getnPrice());
pstmt.setString(17, route.getRemark());
pstmt.setString(18, route.getFromStation());
pstmt.setString(19, route.getToStation());
if (pstmt.executeUpdate() > 0) {
flag = true;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (pstmt != null) {
try {
pstmt.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
return flag;
}
public boolean doUpdateRoute(Route route) throws Exception { //更新车次
boolean flag = false;
PreparedStatement pstmt = null;
String sql = "UPDATE Route SET name = ?, trainType = ?, fromStation = ?, toStation = ?, departureTime = ?, arrivalTime = ?, businessSeatCount = ?, bPrice = ?, specialSeatCount = ?, spPrice = ?, softSeatCount = ?,sfPrice = ?,hardSeatCount = ?,hPrice = ?,noSeatCount = ?,nPrice = ? ,remark = ? WHERE id = ?";
try {
pstmt = this.conn.prepareStatement(sql);
pstmt.setString(1, route.getName());
pstmt.setString(2, route.getType());
pstmt.setString(3, route.getFromStation());
pstmt.setString(4, route.getToStation());
pstmt.setTimestamp(5, new java.sql.Timestamp(route.getDepartureTime().getTime()));
pstmt.setTimestamp(6, new java.sql.Timestamp(route.getArrivalTime().getTime()));
pstmt.setInt(7, route.getBusinessSeatCount());
pstmt.setInt(8, route.getbPrice());
pstmt.setInt(9,route.getSpecialSeatCount());
pstmt.setInt(10, route.getSpPrice());
pstmt.setInt(11, route.getSoftSeatCount());
pstmt.setInt(12, route.getSfPrice());
pstmt.setInt(13, route.getHardSeatCount());
pstmt.setInt(14, route.gethPrice());
pstmt.setInt(15, route.getNoSeatCount());
pstmt.setInt(16, route.getnPrice());
pstmt.setString(17, route.getRemark());
pstmt.setLong(18, route.getId());
if (pstmt.executeUpdate() > 0) {
flag = true;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (pstmt != null) {
try {
pstmt.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
return flag;
}
public boolean doDeleteRoute(Long routeid) throws Exception {
boolean flag = false;
PreparedStatement pstmt = null;
String sql = "DELETE FROM Route WHERE id = ?";
try {
pstmt = this.conn.prepareStatement(sql);
pstmt.setLong(1, routeid);
if (pstmt.executeUpdate() > 0) {
flag = true;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (pstmt != null) {
try {
pstmt.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
return flag;
}
public List<Route> findRoute(String fromStation,String toStation,Date departureTime) throws Exception { //查询车次
List<Route> all = new ArrayList<Route>();
PreparedStatement pstmt = null;
String sql = "SELECT * FROM route WHERE fromStation = ? and toStation = ? and departureTime LIKE ? ";
try {
pstmt = this.conn.prepareStatement(sql);
pstmt.setString(1, fromStation);
pstmt.setString(2, toStation);
pstmt.setString(3, departureTime+"%");
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
Route route = new Route();
route.setId(rs.getLong(1));
route.setName(rs.getString(2));
route.setType(rs.getString(3));
route.setFromStation(rs.getString(4));
route.setToStation(rs.getString(5));
route.setDepartureTime(rs.getTimestamp(6));
route.setArrivalTime(rs.getTimestamp(7));
route.setBusinessSeatCount(rs.getInt(8));
route.setbPirce(rs.getInt(9));
route.setSpecialSeatCount(rs.getInt(10));
route.setSpPrice(rs.getInt(11));
route.setSoftSeatCount(rs.getInt(12));
route.setSfPrice(rs.getInt(13));
route.setHardSeatCount(rs.getInt(14));
route.sethPrice(rs.getInt(15));
route.setNoSeatCount(rs.getInt(16));
route.setnPrice(rs.getInt(17));
route.setRemark(rs.getString(18));
route.setFromStationId(rs.getLong(19));
route.setToStationId(rs.getLong(20));
all.add(route);
}
rs.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (pstmt != null) {
try {
pstmt.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
return all;
}
public List<Route> findAllRoute() throws Exception { //查询车次
List<Route> all = new ArrayList<Route>();
PreparedStatement pstmt = null;
String sql = "SELECT * FROM route ";
try {
pstmt = this.conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
Route route = new Route();
route.setId(rs.getLong(1));
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
一、项目运行 环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持) 项目技术: JSP + Servlert + html+ css + JavaScript + JQuery + Ajax 等等;
资源推荐
资源详情
资源评论
收起资源包目录
Java项目:火车票预订系统(java+JDBC+JSP+Servlet+html+mysql) (277个子文件)
RouteImpl.class 11KB
OrderImpl.class 9KB
TicketImpl.class 9KB
CreateTicketServlet.class 6KB
PayOrderServlet.class 6KB
Route.class 5KB
UserImpl.class 5KB
StationLinkImpl.class 5KB
UpdateRouteServlet.class 5KB
StationImpl.class 5KB
CreateRouteServlet.class 4KB
RefundTicketServlet.class 4KB
ADRegisterServlet.class 4KB
CreateOrderServlet.class 4KB
ADUpdateUserServlet.class 4KB
IOrderDAOProxy.class 4KB
RegisterServlet.class 4KB
IRouteDAOProxy.class 4KB
UpdateProfileServlet.class 4KB
ITicketDAOProxy.class 4KB
ADQueryRouteServlet.class 3KB
QueryRouteAtoBServlet.class 3KB
ADQueryTicketServlet.class 3KB
LoginServlet.class 3KB
Ticket.class 3KB
ChangePasswordServlet.class 3KB
User.class 3KB
CreateStationServlet.class 3KB
QueryTicketServlet.class 3KB
QueryOrderByUserServlet.class 3KB
DeleteRouteServlet.class 3KB
Order.class 3KB
DeleteUserServlet.class 3KB
QueryAllUserInfoServlet.class 2KB
UpdateStationServlet.class 2KB
IStationLinkDAOProxy.class 2KB
IStationDAOProxy.class 2KB
PostSessionServlet.class 2KB
ResetPasswordServlet.class 2KB
DeleteStationServlet.class 2KB
ADQueryStationServlet.class 2KB
QueryUserInfoServlet.class 2KB
QueryStationServlet.class 2KB
IUserDAOProxy.class 2KB
QueryOrderByIdServlet.class 2KB
CharsetFilter.class 2KB
QueryRouteFromServlet.class 2KB
QueryAllOrderServlet.class 2KB
QueryAllStationServlet.class 2KB
RouteStation.class 2KB
StationLink.class 1KB
ExitServlet.class 1KB
CharsetFilter$1.class 1KB
DBConnection.class 1KB
DAOFactory.class 1KB
QueryOrderByTimeServlet.class 1KB
Station.class 1KB
RouteDAO.class 1KB
OrderDAO.class 1KB
TicketDAO.class 1018B
ChangeTicketServlet.class 906B
StationDAO.class 612B
StationLinkDAO.class 568B
UserDAO.class 484B
.classpath 3KB
org.eclipse.wst.common.component 482B
org.eclipse.wst.jsdt.ui.superType.container 49B
bootstrap.css 144KB
bootstrap.min.css 120KB
bootstrap-theme.css 26KB
bootstrap-theme.min.css 23KB
datepicker.css 4KB
datepicker.css 4KB
lgPanel.css 2KB
promptPanel.css 1KB
sysmlgPanel.css 1KB
oplgPanel.css 1KB
lgePanel.css 1KB
RegisterPanel.css 1KB
rpPanel.css 1KB
lpPanel.css 995B
ModifyPasswordPanel.css 587B
WdatePicker.css 192B
timer火车票售票数据库文档.doc 349KB
glyphicons-halflings-regular.eot 20KB
back.gif 524KB
123.gif 437KB
7.gif 274KB
6.gif 10KB
img.gif 2KB
img.gif 2KB
datePicker.gif 1KB
Main.html 8KB
userRegister.html 7KB
queryticket1.html 6KB
resetpassword.html 6KB
userlogin.html 6KB
modifypassword.html 5KB
introduce.html 2KB
mysql-connector-java-5.1.39-bin.jar 966KB
共 277 条
- 1
- 2
- 3
资源评论
- m0_477755252022-06-02用户下载后在一定时间内未进行评价,系统默认好评。
OldWinePot
- 粉丝: 8924
- 资源: 420
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功