这是前面发表的javaweb版本答答租车系统的源代码,因为发表文章有字数限制以及还有功能没扩展出来,因此这里只是一部分,后面还会有文章继续发表的

好了,首先javaweb项目是需要操作数据库的,因此需要建立对应的表来存放对应的数据,这里是四个表分别对应保存不同的数据(因为是源代码,所以直接是建表SQL语句了)

这是car_user表用来存放用户信息的

CREATE TABLE car_user (

id INT(10) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,

username varchar(50) NOT NULL,

password varchar(50) NOT NULL,

sex varchar(10) NOT NULL,

tel varchar(50) NOT NULL,

email varchar(50) NOT NULL,

competence varchar(100) NOT NULL

)

这是car_commodity表用来存放商品信息的

CREATE TABLE car_commodity(

id INT(10) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,

name varchar(50) NOT NULL,

rent int(50) NOT NULL,

manned int(50) NOT NULL,

cargo int(50) NOT NULL,

owner varchar(100) NOT NULL

)

这是car_bill表用来存放用户账单的

CREATE TABLE car_bill(

id INT(10) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,

userid int(10) NOT NULL,

carid int(10) NOT NULL,

quantity int(50) NOT NULL,

totalrent double(100) NOT NULL,

carstatus varchar(100) NOT NULL,

ordernumber varchar(100) NOT NULL,

cartime varchar(100) NOT NULL

)

这是car_account 表用来存放用户账户信息的

CREATE TABLE car_account (

id INT(10) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,

userid int(10) not null,

money varchar(30) not null,

let_frequency int(20) not null,

out_frequency int(20) not null

)

数据库之后就是建立web项目CarSystem了,在项目中创建com.david包用来存放4个数据库对应的4个实体类,为了解决程序乱码问题这里创建com.david.code包用来存放CharacterEncodingFilter.java字符编码过滤器,创建com.david.dao包用来存放4个实体类对应的数据库操作类以及连接数据库文件ConnectSJK.java,最后创建com.david.servlet用来存放所有的Servlet。

这是用户实体类User

package com.david;

/**

* 用户实体类

* @author David

*/

public class User {

private Integer id; //用户id

private String username; //用户名

private String password; //密码

private String sex; //性别

private String tel; //电话

private String email; //邮箱

private String competence; //权限

private Account account; //关联类

public User(){

super();

}

public Integer getId() {

return id;

}

public void setId(Integer id) {

this.id = id;

}

public String getUsername() {

return username;

}

public void setUsername(String username) {

this.username = username;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

public String getSex() {

return sex;

}

public void setSex(String sex) {

this.sex = sex;

}

public String getTel() {

return tel;

}

public void setTel(String tel) {

this.tel = tel;

}

public String getEmail() {

return email;

}

public void setEmail(String email) {

this.email = email;

}

public String getCompetence() {

return competence;

}

public void setCompetence(String competence) {

this.competence = competence;

}

public Account getAccount() {

return account;

}

public void setAccount(Account account) {

this.account = account;

}

@Override

public String toString() {

return "User [id=" + id + ", username=" + username + ", password="

+ password + ", sex=" + sex + ", tel=" + tel + ", email="

+ email + ", competence=" + competence + ", account=" + account

+ "]";

}

@Override

public int hashCode() {

final int prime = 31;

int result = 1;

result = prime * result + ((account == null) ? 0 : account.hashCode());

result = prime * result

+ ((competence == null) ? 0 : competence.hashCode());

result = prime * result + ((email == null) ? 0 : email.hashCode());

result = prime * result + ((id == null) ? 0 : id.hashCode());

result = prime * result

+ ((password == null) ? 0 : password.hashCode());

result = prime * result + ((sex == null) ? 0 : sex.hashCode());

result = prime * result + ((tel == null) ? 0 : tel.hashCode());

result = prime * result

+ ((username == null) ? 0 : username.hashCode());

return result;

}

@Override

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

User other = (User) obj;

if (account == null) {

if (other.account != null)

return false;

} else if (!account.equals(other.account))

return false;

if (competence == null) {

if (other.competence != null)

return false;

} else if (!competence.equals(other.competence))

return false;

if (email == null) {

if (other.email != null)

return false;

} else if (!email.equals(other.email))

return false;

if (id == null) {

if (other.id != null)

return false;

} else if (!id.equals(other.id))

return false;

if (password == null) {

if (other.password != null)

return false;

} else if (!password.equals(other.password))

return false;

if (sex == null) {

if (other.sex != null)

return false;

} else if (!sex.equals(other.sex))

return false;

if (tel == null) {

if (other.tel != null)

return false;

} else if (!tel.equals(other.tel))

return false;

if (username == null) {

if (other.username != null)

return false;

} else if (!username.equals(other.username))

return false;

return true;

}

}

这是商品实体类Commodity

package com.david;

/**

* 商品实体类

* @author David

*/

public class Commodity {

private Integer id; //商品编号

private String name; //车名

private Integer rent; //租金

private Integer manned; //载人量

private Integer cargo; //载货量

private String owner; //车主

public Commodity(){

super();

}

public Integer getId() {

return id;

}

public void setId(Integer id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public Integer getRent() {

return rent;

}

public void setRent(Integer rent) {

this.rent = rent;

}

public Integer getManned() {

return manned;

}

public void setManned(Integer manned) {

this.manned = manned;

}

public Integer getCargo() {

return cargo;

}

public void setCargo(Integer cargo) {

this.cargo = cargo;

}

public String getOwner() {

return owner;

}

public void setOwner(String owner) {

this.owner = owner;

}

@Override

public String toString() {

return "Commodity [id=" + id + ", name=" + name + ", rent=" + rent

+ ", manned=" + manned + ", cargo=" + cargo + ", owner="

+ owner + "]";

}

@Override

public int hashCode() {

final int prime = 31;

int result = 1;

result = prime * result + ((cargo == null) ? 0 : cargo.hashCode());

result = prime * result + ((id == null) ? 0 : id.hashCode());

result = prime * result + ((manned == null) ? 0 : manned.hashCode());

result = prime * result + ((name == null) ? 0 : name.hashCode());

result = prime * result + ((owner == null) ? 0 : owner.hashCode());

result = prime * result + ((rent == null) ? 0 : rent.hashCode());

return result;

}

@Override

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

Commodity other = (Commodity) obj;

if (cargo == null) {

if (other.cargo != null)

return false;

} else if (!cargo.equals(other.cargo))

return false;

if (id == null) {

if (other.id != null)

return false;

} else if (!id.equals(other.id))

return false;

if (manned == null) {

if (other.manned != null)

return false;

} else if (!manned.equals(other.manned))

return false;

if (name == null) {

if (other.name != null)

return false;

} else if (!name.equals(other.name))

return false;

if (owner == null) {

if (other.owner != null)

return false;

} else if (!owner.equals(other.owner))

return false;

if (rent == null) {

if (other.rent != null)

return false;

} else if (!rent.equals(other.rent))

return false;

return true;

}

}

这是账单实体类Biil

package com.david;

/**

* 账单实体类

* @author David

*/

public class Bill {

private Integer id; //序号

private Integer userid; //用户id

private Integer carid; //车id

private Integer quantity; //租车数量

private Double totalrent; //总租金

private String carstatus; //租车状态

private String cartime; //租车时间

private String ordernumber; //账单编号

private User user;

public Bill(){

super();

}

public Integer getId() {

return id;

}

public void setId(Integer id) {

this.id = id;

}

public Integer getUserid() {

return userid;

}

public void setUserid(Integer userid) {

this.userid = userid;

}

public Integer getCarid() {

return carid;

}

public void setCarid(Integer carid) {

this.carid = carid;

}

public Integer getQuantity() {

return quantity;

}

public void setQuantity(Integer quantity) {

this.quantity = quantity;

}

public Double getTotalrent() {

return totalrent;

}

public void setTotalrent(Double totalrent) {

this.totalrent = totalrent;

}

public String getCarstatus() {

return carstatus;

}

public void setCarstatus(String carstatus) {

this.carstatus = carstatus;

}

public String getCartime() {

return cartime;

}

public void setCartime(String cartime) {

this.cartime = cartime;

}

public String getOrdernumber() {

return ordernumber;

}

public void setOrdernumber(String ordernumber) {

this.ordernumber = ordernumber;

}

public User getUser() {

return user;

}

public void setUser(User user) {

this.user = user;

}

@Override

public String toString() {

return "Bill [id=" + id + ", userid=" + userid + ", carid=" + carid

+ ", quantity=" + quantity + ", totalrent=" + totalrent

+ ", carstatus=" + carstatus + ", cartime=" + cartime

+ ", ordernumber=" + ordernumber + "]";

}

@Override

public int hashCode() {

final int prime = 31;

int result = 1;

result = prime * result + ((carid == null) ? 0 : carid.hashCode());

result = prime * result

+ ((carstatus == null) ? 0 : carstatus.hashCode());

result = prime * result + ((cartime == null) ? 0 : cartime.hashCode());

result = prime * result + ((id == null) ? 0 : id.hashCode());

result = prime * result

+ ((ordernumber == null) ? 0 : ordernumber.hashCode());

result = prime * result

+ ((quantity == null) ? 0 : quantity.hashCode());

result = prime * result

+ ((totalrent == null) ? 0 : totalrent.hashCode());

result = prime * result + ((userid == null) ? 0 : userid.hashCode());

return result;

}

@Override

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

Bill other = (Bill) obj;

if (carid == null) {

if (other.carid != null)

return false;

} else if (!carid.equals(other.carid))

return false;

if (carstatus == null) {

if (other.carstatus != null)

return false;

} else if (!carstatus.equals(other.carstatus))

return false;

if (cartime == null) {

if (other.cartime != null)

return false;

} else if (!cartime.equals(other.cartime))

return false;

if (id == null) {

if (other.id != null)

return false;

} else if (!id.equals(other.id))

return false;

if (ordernumber == null) {

if (other.ordernumber != null)

return false;

} else if (!ordernumber.equals(other.ordernumber))

return false;

if (quantity == null) {

if (other.quantity != null)

return false;

} else if (!quantity.equals(other.quantity))

return false;

if (totalrent == null) {

if (other.totalrent != null)

return false;

} else if (!totalrent.equals(other.totalrent))

return false;

if (userid == null) {

if (other.userid != null)

return false;

} else if (!userid.equals(other.userid))

return false;

return true;

}

}

这是账户实体类Account

package com.david;

/**

* 账户实体类

* @author David

*/

public class Account {

private Integer id; //账户编号

private Integer userid; //用户id

private Double money; //账户余额

private Integer let_frequency; //租车次数

private Integer out_frequency; //出租次数

public Account(){

super();

}

public Integer getId() {

return id;

}

public void setId(Integer id) {

this.id = id;

}

public Integer getUserid() {

return userid;

}

public void setUserid(Integer userid) {

this.userid = userid;

}

public Double getMoney() {

return money;

}

public void setMoney(Double money) {

this.money = money;

}

public Integer getLet_frequency() {

return let_frequency;

}

public void setLet_frequency(Integer let_frequency) {

this.let_frequency = let_frequency;

}

public Integer getOut_frequency() {

return out_frequency;

}

public void setOut_frequency(Integer out_frequency) {

this.out_frequency = out_frequency;

}

@Override

public String toString() {

return "Account [id=" + id + ", userid=" + userid + ", money=" + money

+ ", let_frequency=" + let_frequency + ", out_frequency="

+ out_frequency + "]";

}

@Override

public int hashCode() {

final int prime = 31;

int result = 1;

result = prime * result + ((id == null) ? 0 : id.hashCode());

result = prime * result

+ ((let_frequency == null) ? 0 : let_frequency.hashCode());

result = prime * result + ((money == null) ? 0 : money.hashCode());

result = prime * result

+ ((out_frequency == null) ? 0 : out_frequency.hashCode());

result = prime * result + ((userid == null) ? 0 : userid.hashCode());

return result;

}

@Override

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

Account other = (Account) obj;

if (id == null) {

if (other.id != null)

return false;

} else if (!id.equals(other.id))

return false;

if (let_frequency == null) {

if (other.let_frequency != null)

return false;

} else if (!let_frequency.equals(other.let_frequency))

return false;

if (money == null) {

if (other.money != null)

return false;

} else if (!money.equals(other.money))

return false;

if (out_frequency == null) {

if (other.out_frequency != null)

return false;

} else if (!out_frequency.equals(other.out_frequency))

return false;

if (userid == null) {

if (other.userid != null)

return false;

} else if (!userid.equals(other.userid))

return false;

return true;

}

}

这是用户数据库操作类UserDao

package com.david.dao;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import com.david.User;

/**

* 用户数据库操作类

* @author David

*/

public class UserDao {

/**

* 新增用户

* @param User 用户

* @author David

*/

public void saveUser(User user){

//获取数据库连接Connection对象

Connection conn = ConnectSJK.getConnection();

String sql = "insert into car_user(username,password,sex,tel,email,competence) value (?,?,?,?,?,?)";

try {

//获取preparedstatement对象

PreparedStatement ps = conn.prepareStatement(sql);

//对sql语句占位符参数进行动态赋值

ps.setString(1, user.getUsername());

ps.setString(2, user.getPassword());

ps.setString(3, user.getSex());

ps.setString(4, user.getTel());

ps.setString(6, user.getEmail());

ps.setString(7, user.getCompetence());

//执行更新操作

ps.executeUpdate();

//释放此preparedstatement对象的数据库和JDBC资源

ps.close();

} catch (Exception e) {

// TODO: handle exception

e.printStackTrace();

} finally{

//关闭数据库连接

ConnectSJK.closeConnection(conn);

}

}

/**

* 用户登录

* @param username 用户名

* @param passwrod 密码

* @author David

* @return 用户对象

*/

public User login(String username,String password){

//实例化一个对象

User user = new User();

//获取数据库连接Connection对象

Connection conn = ConnectSJK.getConnection();

//根据用户名和密码查询用户信息

String sql = "select * from car_user where username = ? and password = ?";

try {

//获取preparedStatement对象

PreparedStatement ps = conn.prepareStatement(sql);

//对sql语句的占位符参数进行动态赋值

ps.setString(1, username);

ps.setString(2, password);

//执行查询获取结果集

ResultSet rs = ps.executeQuery();

//判断结果集是否有效

if(rs.next()){

//对用户对象属性赋值

user.setId(rs.getInt("id"));

user.setUsername(rs.getString("username"));

user.setPassword(rs.getString("password"));

user.setSex(rs.getString("sex"));

user.setTel(rs.getString("tel"));

user.setEmail(rs.getString("email"));

user.setCompetence(rs.getString("competence"));

}

//释放此ResultSet对象的数据库和JDBC资源

rs.close();

//释放此preparedStatement对象的数据库和JDBC资源

ps.close();

} catch (Exception e) {

// TODO: handle exception

e.printStackTrace();

} finally{

//关闭数据库连接

ConnectSJK.closeConnection(conn);

}

return user;

}

/**

* 判断用户在数据库中是否存在

* @param username 用户名

* @author David

* @return 布尔值

*/

public boolean userIsExsit(String username){

//获取数据库连接Connection对象

Connection conn = ConnectSJK.getConnection();

//根据指定用户名查询用户信息

String sql = "select * from car_user where username=?";

try {

//获取preparedstatement对象

PreparedStatement ps = conn.prepareStatement(sql);

//对sql占位符参数进行动态赋值

ps.setString(1, username);

//执行查询获取结果集

ResultSet rs = ps.executeQuery();

//判断结果集是否有效

if(!rs.next()){

//如果无效则证明可用

return true;

}

// 释放此 ResultSet 对象的数据库和 JDBC 资源

rs.close();

// 释放此 PreparedStatement 对象的数据库和 JDBC 资源

ps.close();

} catch (Exception e) {

// TODO: handle exception

e.printStackTrace();

} finally{

//关闭数据库连接

ConnectSJK.closeConnection(conn);

}

return false;

}

/**

* 修改资料

* @param user 用户

* @author David

*/

public void modifyUser(User user){

//获取数据库连接Connection对象

Connection conn = ConnectSJK.getConnection();

//插入修改资料的sql语句

String sql = "update car_user set sex=?,tel=?,email=? where username=?";

try {

//获取preparedstatement对象

PreparedStatement ps = conn.prepareStatement(sql);

//对用户对象进行赋值

ps.setString(1, user.getSex());

ps.setString(2, user.getTel());

ps.setString(3, user.getEmail());

ps.setString(4, user.getUsername());

//执行更新操作

ps.executeUpdate();

//释放此preparedstatement对象的数据库和JDBC资源

ps.close();

} catch (Exception e) {

// TODO: handle exception

e.printStackTrace();

} finally{

//关闭数据库连接

ConnectSJK.closeConnection(conn);

}

}

/**

* 根据用户名查id

* @param username 用户名

* @author David

* @return 整数id

*/

public int userid(String username){

//定义变量保存用户id

int userid = 0;

//获取数据库连接Connection对象

Connection conn = ConnectSJK.getConnection();

//根据用户名查询用户id

String sql = "select id from car_user where username=?";

try {

//获取preparedstatement对象

PreparedStatement ps = conn.prepareStatement(sql);

//对sql占位符参数进行动态赋值

ps.setString(1, username);

//执行查询获取结果集

ResultSet rs = ps.executeQuery();

//判断结果集是否有效

if(rs.next()){

//将结果赋值给变量userid

userid = rs.getInt("id");

}

// 释放此 ResultSet 对象的数据库和 JDBC 资源

rs.close();

// 释放此 PreparedStatement 对象的数据库和 JDBC 资源

ps.close();

} catch (Exception e) {

// TODO: handle exception

e.printStackTrace();

} finally{

//关闭数据库连接

ConnectSJK.closeConnection(conn);

}

return userid;

}

}

因为有2W字数限制,后面的会在另一篇文章中继续更新的!

java web租车系统_javaweb版本的答答租车系统 (源代码一)相关推荐

  1. java web配置dll文件_JavaWeb项目中dll文件动态加载方法解析(详细步骤)

    相信很多做Java的朋友都有过用Java调用JNI实现调用C或C++方法的经历,那么Java Web中又如何实现DLL/SO文件的动态加载方法呢.今天就给大家带来一篇JAVA Web项目中DLL/SO ...

  2. java web部署文档_javaweb项目实施部署文档

    javaweb项目实施部署文档 一 .安装配置jdk Jdk的下载地址: http://www.oracle.com/technetwork/java/javase/downloads/index.h ...

  3. java web pdf 下载文件_javaWeb实现文件上传和下载.pdf

    jjaavvaaWWeebb实实现现文文件件上上传传与与下下载载 文件上传概述 实现web开发中的文件上传功能,需完成如下二步操作: 在web页面中添加上传输入项 在servlet 中读取上传文件的数 ...

  4. Java web技术的驾校培训管理软件之预约排班子系统

    第四章  系统设计 4.1演示地址 点击查看 4.1.1管理员设置课程流程 管理员登录后会有课程设置的选项,点击该选项会跳出课程设置界面,可以进行课程的设置,如输入课程不合法会有相应的提示,直至输入正 ...

  5. java web开发周志_javaweb学习笔记及周报告

    第三周: 1.html(HyperText Markup Language:超文本标记语言 ):网页语言. (1)解释名词 a.超文本:超出文本的范畴,使用html可以轻松实现类似使文字带颜色的操作: ...

  6. java web 项目导入因为jdk版本出现红色大感叹号

           今天导入一个别人给的项目,出现了红色大感叹号,上网查了一下问题,但是感觉回答很分散,看了两个博客才完全解决,为了大家方便,所以来整合一下. 简而言之,需要如下三步: 1.删除项目中之前的 ...

  7. java web 文件上传_Javaweb学习笔记10—文件上传与下载

    今天来讲javaweb的第10阶段学习.文件的上传与下载,今天主要说的是这个功能的实现,不用说了,听名字就是外行人也知道肯定很重要啦. 老规矩,首先先用一张思维导图来展现今天的博客内容. ps:我的思 ...

  8. java web 设计模式之道_JavaWeb之MVC设计模式

    时间:2016-11-26 16:22 --MVC MVC模式(Model - View - Controller)是软件工程中的一种架构模式,把软件系统分为三个基本部分: 模型(Model).视图( ...

  9. java web的友好页面_JavaWeb 之 由 Tomcat 展示友好的错误信息页面

    在 JavaWeb 工程中,可能会遇到 404 或 500 的错误页面,也有可能是由于异常显示的空白页面,但是此时并不想把这些页面给用户呈现出来,这时就需要给用户提示一些友好的信息. 在部署 Java ...

最新文章

  1. 简单分析beyond作曲
  2. 【组合数学】生成函数 ( 求和性质 )
  3. Spring Boot Actuator:在其顶部具有MVC层的自定义端点
  4. Matlab图像处理相关
  5. docker学习1--dockerfile
  6. Effective C++(9) 构造函数调用virtual函数会发生什么
  7. 小红书面试题——paddingNum,用逗号分割数字串
  8. [转]Directx11 3D空间坐标系认识
  9. c语言sqrt函数无作用,如何在不使用C语言的sqrt函数的情况下获得数字的平方根...
  10. SSM框架整合(参考尚硅谷视频和文档
  11. 我的世界pc要安装java_我的世界安装教程 PC版新手安装攻略
  12. 海康大华PC客户端集成播放器
  13. 关于新闻:西瓜3毛一斤仍滞销 被当垃圾扔掉 问题的一点看法
  14. oracle list分区添加,oracle 11g 如何创建、修改、删除list-list组合分区
  15. 神经网络控制与matlab仿真,神经网络matlab代码程序
  16. 老式门锁改wifi遥控开门
  17. 学习Linux你必须知道的那些事儿
  18. 偏差-方差权衡(bias-variance-tradeoff)
  19. 基于匹配点集对单应性矩阵进行估计
  20. 如何参与linux内核开发

热门文章

  1. 我是如何突围传统行业的?
  2. mac安装charls工具
  3. ducter运维平台_开源自动运维管理平台_自动化运维平台 开源
  4. 数字源表测试太阳能电池片单通道多通道方案
  5. 鸿蒙系统究竟是PPT秀还是有真材实料?鸿蒙HarmonyOS开发环境搭建与运行Demo
  6. ASCII码128-255扩展编码显示奇葩中文的原因
  7. 全国各省市县 人口密度 数据 下载 空间数据 高精度 空间分布数据 多年 人口热力图 地理信息 GIS...
  8. 单例模式在DRP中的应用
  9. Camtasia——录制教程的神器
  10. 02-Vue-cli 环境搭建