以JavaWeb实现订票.docx
《以JavaWeb实现订票.docx》由会员分享,可在线阅读,更多相关《以JavaWeb实现订票.docx(48页珍藏版)》请在冰点文库上搜索。
以JavaWeb实现订票
JavaWeb附录
一.数据库展示
User数据库
Plane数据库
Book数据库
二.代码展示
数据库User部分
packageuser;
publicclassUserVO{
privateStringusername;//用户注册姓名
privateStringusertruename;//用户真实姓名
privateStringuserpass;//登录密码
privateStringusergender;//性别
privateStringuserIDCard;//用户身份证号
privateStringuserphonenum;//用户电话号码
privateStringuseremail;//电子邮件
publicStringgetUserpass(){
returnuserpass;
}
publicvoidsetUserpass(Stringuserpass){
this.userpass=userpass;
}
publicStringgetUsername(){
returnusername;
}
publicvoidsetUsername(Stringusername){
this.username=username;
}
publicStringgetUsertruename(){
returnusertruename;
}
publicvoidsetUsertruename(Stringusertruename){
this.usertruename=usertruename;
}
publicStringgetUserIDCard(){
returnuserIDCard;
}
publicvoidsetUserIDCard(StringuserIDCard){
this.userIDCard=userIDCard;
}
publicStringgetUserphonenum(){
returnuserphonenum;
}
publicvoidsetUserphonenum(Stringuserphonenum){
this.userphonenum=userphonenum;
}
publicStringgetUsergender(){
returnusergender;
}
publicvoidsetUsergender(Stringusergender){
this.usergender=usergender;
}
publicStringgetUseremail(){
returnuseremail;
}
publicvoidsetUseremail(Stringuseremail){
this.useremail=useremail;
}
}
packageuser;
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.PreparedStatement;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.sql.Statement;
importjava.util.ArrayList;
publicclassuserAction{
StringsDbDriver="sun.jdbc.odbc.JdbcOdbcDriver";
StringsConneStr="jdbc:
odbc:
user";
Connectioncon;
privateUserVOuse;
publicUserVOgetUse(){
returnuse;
}
publicvoidsetUse(UserVOuse){
this.use=use;
}
publicuserAction(){
try{
Class.forName(sDbDriver);//加载驱动程序
con=DriverManager.getConnection(sConneStr);//数据库连接
}
catch(Exceptione){
System.err.print(e.getMessage());
}
}
publicConnectiongetConn()throwsSQLException{
returnDriverManager.getConnection(sConneStr);
}
//查询所有用户
publicArrayListgetAllUsers(){
ArrayListusers=newArrayList();
try{
Statementstm=con.createStatement();//获得statement对象
ResultSetresult=stm.executeQuery("select*fromuser");//利用statement对象查询结果
while(result.next()){
Stringusername=result.getString("用户名");
Stringusertruename=result.getString("真实姓名");
Stringuserpass=result.getString("密码");
Stringusergender=result.getString("性别");
StringuserIDCard=result.getString("用户身份证号");
Stringuserphonenum=result.getString("用户电话号码");
Stringuseremail=result.getString("电子邮件");
UserVOuser=newUserVO();
user.setUsername(username);
user.setUsertruename(usertruename);
user.setUserpass(userpass);
user.setUsergender(usergender);
user.setUserIDCard(userIDCard);
user.setUserphonenum(userphonenum);
user.setUseremail(useremail);
users.add(user);
}
result.close();
stm.close();
//con.close();
}
catch(Exceptione){
}
returnusers;
}
//增加用户
publicvoidaddUsers(){
try{
PreparedStatementpstmt=getConn().prepareStatement("insertintouservalues(?
?
?
?
?
?
?
)");
pstmt.setString(1,use.getUsername());
pstmt.setString(2,use.getUsertruename());
pstmt.setString(3,use.getUserpass());
pstmt.setString(4,use.getUsergender());
pstmt.setString(5,use.getUserIDCard());
pstmt.setString(6,use.getUserphonenum());
pstmt.setString(7,use.getUseremail());
try{
pstmt.executeUpdate();
}
catch(Exceptione){
System.out.println("插入出错了!
");
}
con.close();
}
catch(Exceptione){
e.printStackTrace();
}
}
//修改用户信息
publicvoidupdateUsers(Stringusername,Stringmodify,Stringcontent){//
try{
PreparedStatementstm=null;
if(modify.equals("电话号码")){
stm=getConn().prepareStatement("updateuserset用户电话号码='"+content+"'where用户名='"+username+"'");
}
elseif(modify.equals("密码")){
stm=getConn().prepareStatement("updateuserset密码='"+content+"'where用户名='"+username+"'");
}
elseif(modify.equals("电子邮件")){
stm=getConn().prepareStatement("updateuserset电子邮件='"+content+"'where用户名='"+username+"'");
}
stm.executeUpdate();
con.close();
stm.close();
}
catch(Exceptione){
e.printStackTrace();
}
}
}
数据库plane部分
packageplane;
publicclassPlaneVO{
privateStringplaneID;//航班ID
privateStringplanefrom;//出发地
privateStringplaneto;//目的地
privateStringplanestarttime;//起始时间
privateStringplaneflytime;//飞行时间
privateintplaneprice;//机票价格
privateintplaneinsurrance;//飞机保险
publicStringgetPlaneID(){
returnplaneID;
}
publicvoidsetPlaneID(StringplaneID){
this.planeID=planeID;
}
publicStringgetPlanefrom(){
returnplanefrom;
}
publicvoidsetPlanefrom(Stringplanefrom){
this.planefrom=planefrom;
}
publicStringgetPlaneto(){
returnplaneto;
}
publicvoidsetPlaneto(Stringplaneto){
this.planeto=planeto;
}
publicStringgetPlanestarttime(){
returnplanestarttime;
}
publicvoidsetPlanestarttime(Stringplanestarttime){
this.planestarttime=planestarttime;
}
publicStringgetPlaneflytime(){
returnplaneflytime;
}
publicvoidsetPlaneflytime(Stringplaneflytime){
this.planeflytime=planeflytime;
}
publicintgetPlaneprice(){
returnplaneprice;
}
publicvoidsetPlaneprice(intplaneprice){
this.planeprice=planeprice;
}
publicintgetPlaneinsurrance(){
returnplaneinsurrance;
}
publicvoidsetPlaneinsurrance(intplaneinsurrance){
this.planeinsurrance=planeinsurrance;
}
}
packageplane;
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.ResultSet;
importjava.sql.Statement;
importjava.util.ArrayList;
publicclassplaneAction{
StringsDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
StringsConnestr="jdbc:
odbc:
plane";
Connectioncon;
privatePlaneVOplan;
publicPlaneVOgetPlan(){
returnplan;
}
publicvoidsetPlan(PlaneVOplan){
this.plan=plan;
}
publicplaneAction(){
try{
Class.forName(sDBDriver);
con=DriverManager.getConnection(sConnestr);
}
catch(Exceptione){
System.err.print(e.getMessage());
}
}
//查询所有航班
publicArrayListgetAllplanes(){
ArrayListplanes=newArrayList();
try{
Statementstm=con.createStatement();
ResultSetresult=stm.executeQuery("select*fromplane");
while(result.next()){
StringplaneID=result.getString("航班ID");
Stringplanefrom=result.getString("出发地");
Stringplaneto=result.getString("目的地");
Stringplanestarttime=result.getString("出发时间");
Stringplaneflytime=result.getString("运行时间");
intplaneprice=result.getInt("价格");
intplaneinsurrance=result.getInt("保险");
PlaneVOplane=newPlaneVO();
plane.setPlaneID(planeID);
plane.setPlanefrom(planefrom);
plane.setPlaneto(planeto);
plane.setPlanestarttime(planestarttime);
plane.setPlaneflytime(planeflytime);
plane.setPlaneprice(planeprice);
plane.setPlaneinsurrance(planeinsurrance);
planes.add(plane);
}
result.close();
stm.close();
con.close();
}
catch(Exceptione){
e.printStackTrace();
}
returnplanes;
}
}
数据库book部分
packagebook;
publicclassBookVO{
privateStringusername;//用户ID
privateStringplaneID;//航班ID
privateintordernum;//票数
privateintorderprice;//价格
privateStringinsurrance;//保险
publicStringgetUsername(){
returnusername;
}
publicvoidsetUsername(Stringusername){
this.username=username;
}
publicStringgetPlaneID(){
returnplaneID;
}
publicvoidsetPlaneID(StringplaneID){
this.planeID=planeID;
}
publicintgetOrdernum(){
returnordernum;
}
publicvoidsetOrdernum(intordernum){
this.ordernum=ordernum;
}
publicintgetOrderprice(){
returnorderprice;
}
publicvoidsetOrderprice(intorderprice){
this.orderprice=orderprice;
}
publicStringgetInsurrance(){
returninsurrance;
}
publicvoidsetInsurrance(Stringinsurrance){
this.insurrance=insurrance;
}
}
packagebook;
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.PreparedStatement;
importjava.sql.ResultSet;
importjava.sql.Statement;
importjava.util.ArrayList;
publicclassbookAction{
StringsDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
StringsConnestr="jdbc:
odbc:
book";
Connectioncon;
privateBookVOord;
publicBookVOgetOrd(){
returnord;
}
publicvoidsetOrd(BookVOord){
this.ord=ord;
}
publicbookAction(){
try{
Class.forName(sDBDriver);
con=DriverManager.getConnection(sConnestr);
}
catch(Exceptione){
System.err.print(e.getMessage());
}
}
//查询所有订单
publicArrayListgetAllorders(){
ArrayListorders=newArrayList();
try{
Statementstm=con.createStatement();
ResultSetresult=stm.executeQuery("select*frombook");
while(result.next()){
Stringusername=result.getString("用户名");
StringplaneID=result.getString("航班ID");
intordernum=result.getInt("票数");
intorderprice=result.getInt("价格");
Stringinsurrance=result.getString("保险");
BookVOorder=newBookVO();
order.setUsername(username);
order.setPlaneID(planeID);
order.setOrdernum(ordernum);
order.setOrderprice(orderprice);
order.setInsu