package com.rentCarSystem.persist;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.rentCarSystem.commons.Constants;
import com.rentCarSystem.commons.JdbcUtil;
import com.rentCarSystem.commons.Page;
import com.rentCarSystem.commons.Tools;
import com.rentCarSystem.domain.Car;
import com.rentCarSystem.domain.Customers;
import com.rentCarSystem.domain.RentTable;
import com.rentCarSystem.domain.User;
import com.rentCarSystem.exception.SystemError;
import com.rentCarSystem.exception.SystemException;
public class RentTableDaoImpl implements RentTableDao {
/**
* 单例模式
*/
private static RentTableDao rentDao = new RentTableDaoImpl();
private RentTableDaoImpl() {
}
public static RentTableDao getInstance() {
return rentDao;
}
// 业务统计中查询全部出租单信息
public Page findRentTable(int pageIndex) {
Connection conn = null;
Page p = new Page();
RentTable rent = null;
String custId = null;
String carId = null;
String userId = null;
try {
conn = JdbcUtil.getConnection();
int from = (pageIndex - 1) * Constants.PAGE_NUMBER + 1;
int to = pageIndex * Constants.PAGE_NUMBER;
PreparedStatement ps = conn.prepareStatement(this.genSQL(from, to));
ResultSet rs = ps.executeQuery();
while (rs.next()) {
rent = new RentTable();
rent.setTableId(rs.getLong("tableid"));
rent.setShouldPayPrice(rs.getDouble("shouldpayprice"));
rent.setPrice(rs.getDouble("price"));
rent.setBeginDate(rs.getDate("begindate"));
rent.setShouldReturnDate(rs.getDate("shouldreturndate"));
rent.setReturnDate(rs.getDate("returndate"));
rent.setRentFlag(rs.getInt("rentflag"));
rent.setCustId(rs.getString("custid"));
rent.setCarId(rs.getString("carid"));
rent.setUserId(rs.getString("userid"));
custId = rs.getString("custid");
carId = rs.getString("carid");
userId = rs.getString("userid");
if (custId != null && custId.length() > 0) {
PreparedStatement ps2 = conn
.prepareStatement("select * from customers where identity=?");
ps2.setString(1, custId);
ResultSet rs2 = ps2.executeQuery();
while (rs2.next()) {
Customers customer = new Customers();
customer.setIdentity(rs2.getString("identity"));
customer.setCustName(rs2.getString("custname"));
customer.setSex(rs2.getString("sex"));
customer.setAddress(rs2.getString("address"));
customer.setPhone(rs2.getString("phone"));
customer.setCareer(rs2.getString("career"));
customer.setCustPwd(rs2.getString("custpwd"));
rent.setCustomers(customer);
}
}
if (carId != null && carId.length() > 0) {
PreparedStatement ps3 = conn
.prepareStatement("select * from cars where carnumber=?");
ps3.setString(1, carId);
ResultSet rs3 = ps3.executeQuery();
while (rs3.next()) {
Car car = new Car();
car.setCarNumber(rs3.getString("carnumber"));
car.setCarType(rs3.getString("cartype"));
car.setColor(rs3.getString("color"));
car.setPrice(rs3.getString("price"));
car.setRentPrice(rs3.getString("rentprice"));
car.setDeposit(rs3.getString("deposit"));
car.setIsRenting(rs3.getString("isrenting"));
car.setDescription(rs3.getString("cardesc"));
rent.setCar(car);
}
}
if (userId != null && userId.length() > 0) {
PreparedStatement ps4 = conn
.prepareStatement("select * from users where username=?");
ps4.setString(1, userId);
ResultSet rs4 = ps4.executeQuery();
while (rs4.next()) {
User user = new User();
user.setUserName(rs4.getString("username"));
user.setIdentity(rs4.getString("identity"));
user.setFullName(rs4.getString("fullname"));
user.setSex(rs4.getString("sex"));
user.setAddress(rs4.getString("address"));
user.setPhone(rs4.getString("phone"));
user.setPosition(rs4.getString("position"));
user.setUserLevel(rs4.getInt("userlevel"));
user.setUserPwd(rs4.getString("userpwd"));
rent.setUser(user);
}
}
p.getResult().add(rent);
}
if (p.getResult().size() > 0) {
PreparedStatement ps2 = conn
.prepareStatement("select count(*) c from renttable rent, cars car, users users, customers cust where rent.custid=cust.identity and rent.carid=car.carnumber and rent.userid=users.username");
ResultSet rs2 = ps2.executeQuery();
int countTemp = -1;
while (rs2.next()) {
countTemp = rs2.getInt("c");
}
if (countTemp != -1) {
int totalPage = 0;
if (countTemp % Constants.PAGE_NUMBER == 0) {
totalPage = countTemp / Constants.PAGE_NUMBER;
} else {
totalPage = countTemp / Constants.PAGE_NUMBER + 1;
}
p.setCurrPage(pageIndex);
p.setTotalPage(totalPage);
p.setCountRow(countTemp);
}
}
} catch (SQLException e) {
JdbcUtil.rollbackConnection(conn);
throw new SystemException("sql语句出错");
} catch (Exception e) {
if (e.toString().indexOf("SystemException") != -1) {
throw new SystemException(e.getMessage());
} else {
JdbcUtil.rollbackConnection(conn);
throw new SystemError("数据库访问失败");
}
} finally {
JdbcUtil.closeConnection(conn);
}
return p;
}
// 分页信息
private String genSQL(int from, int to) {
StringBuffer sb = new StringBuffer("select t.* from (");
sb
.append(
"select rownum rn,rent.tableid,rent.imprest,rent.shouldpayprice,rent.price,rent.begindate,rent.shouldreturndate,rent.returndate,rent.rentflag,rent.custid,rent.carid,rent.userid from renttable rent, cars car, users users, customers cust where rent.custid=cust.identity and rent.carid=car.carnumber and rent.userid=users.username")
.append(")t where t.rn between ").append(from).append(" and ")
.append(to);
return sb.toString();
}
// 业务统计中查询单个出租单信息
public RentTable findRentTable(Long tableId, String custId, String carId,
String userId) {
Connection conn = null;
RentTable rent = null;
try {
conn = JdbcUtil.getConnection();
PreparedStatement ps = conn
.prepareStatement("select * from renttable where tableid=?");
ps.setLong(1, tableId);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
rent = new RentTable();
rent.setTableId(rs.getLong("tableid"));
rent.setImprest(rs.getDouble("imprest"));
rent.setShouldPayPrice(rs.getDouble("shouldpayprice"));
rent.setPrice(rs.getDouble("price"));
rent.setBeginDate(rs.getDate("begindate"));
rent.setShouldReturnDate(rs.getDate("shouldreturndate"));
rent.setReturnDate(rs.getDate("returndate"));
rent.setRentFlag(rs.getInt("rentflag"));
rent.setCustId(rs.getString("custid"));
rent.setCarId(rs.getString("carid"));
rent.setUserId(rs.getString("userid"));
if (custId != null && custId.length() > 0) {
PreparedStatement ps2 = conn
.prepareStatement("select * from customers where identity=?");
ps2.setString(1, custId);
ResultSet rs2 = ps2.executeQuery();
while (rs2.next()) {
Customers customer = new Customers();
customer.setIdentity(rs2.getString("identity"));
customer.setCustName(rs2.getString("custname"));
customer.setSex(rs2.getString("sex"));
customer.setAddress(rs2.getString("address"));
customer.setPhone(rs2.getString("phone"));
customer.setCareer(rs2.getString("career"));
customer.setCustPwd(rs2.getString("custpwd"));
rent.setCustomers(customer);
}
}
if (carId != null && carId.length() > 0) {
PreparedStatement ps3 = conn
.prepareStatement("select * from cars where
没有合适的资源?快使用搜索试试~ 我知道了~
JAVA汽车租赁系统源码
共1174个文件
svn-base:581个
java:105个
class:103个
1星 需积分: 50 32 下载量 60 浏览量
2019-03-16
14:09:29
上传
评论 6
收藏 5.52MB RAR 举报
温馨提示
JAVA汽车租赁系统源码
资源推荐
资源详情
资源评论
收起资源包目录
JAVA汽车租赁系统源码 (1174个子文件)
all-wcprops 8KB
all-wcprops 6KB
all-wcprops 3KB
all-wcprops 3KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 980B
all-wcprops 795B
all-wcprops 790B
all-wcprops 790B
all-wcprops 782B
all-wcprops 776B
all-wcprops 767B
all-wcprops 767B
all-wcprops 724B
all-wcprops 688B
all-wcprops 650B
all-wcprops 634B
all-wcprops 621B
all-wcprops 621B
all-wcprops 617B
all-wcprops 582B
all-wcprops 564B
all-wcprops 564B
all-wcprops 552B
all-wcprops 552B
all-wcprops 536B
all-wcprops 518B
all-wcprops 505B
all-wcprops 505B
all-wcprops 502B
all-wcprops 468B
all-wcprops 413B
all-wcprops 375B
all-wcprops 368B
all-wcprops 354B
all-wcprops 351B
all-wcprops 308B
all-wcprops 278B
all-wcprops 208B
all-wcprops 202B
all-wcprops 196B
all-wcprops 196B
all-wcprops 103B
all-wcprops 103B
all-wcprops 99B
all-wcprops 99B
all-wcprops 94B
all-wcprops 85B
all-wcprops 85B
RentTableDaoImpl.class 15KB
CheckTableDaoImpl.class 12KB
UserDaoImpl.class 11KB
CarDaoImpl.class 9KB
CustomersDaoImpl.class 8KB
RoleDaoImpl.class 8KB
AddCarServlet.class 5KB
LogsDaoImpl.class 5KB
CreateRentCarTableServlet.class 5KB
ValidateCodeServlet.class 4KB
UpdeateRentTable.class 4KB
CreateCheckTableServlet.class 4KB
UpdateCarServlet.class 4KB
FindAllCheckTable.class 4KB
FindCheckTableById.class 4KB
FindAllCarServlet.class 4KB
UpdateRoleServlet.class 4KB
FindAllCustomersServlet.class 4KB
RentTable.class 4KB
AddCustomersServlet.class 4KB
FindAllRentCarTable.class 4KB
PreCreateRentCarTableServlet.class 4KB
FindUserServlet.class 3KB
User.class 3KB
AddRoleServlet.class 3KB
UpdateCustomersServlet.class 3KB
FindRentCarTableById.class 3KB
RoleManagerImpl.class 3KB
FindRoleServlet.class 3KB
UpdateCheckTable.class 3KB
AddUserServlet.class 3KB
UpdateUserServlet.class 3KB
LoginUserServlet.class 3KB
共 1174 条
- 1
- 2
- 3
- 4
- 5
- 6
- 12
资源评论
- Oftentap-米点联系人2019-05-15还我分数,完全没用啊,客服快下架,还我分数@醉酒青牛2019-05-24上传者没有删除这个资源的权限...@醉酒青牛2019-05-24抱歉, 有可能是压缩时候出错了或者搞错了资源
@醉酒青牛
- 粉丝: 11
- 资源: 102
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功