汽车管理系统的模拟全部代码.docx
- 文档编号:26498605
- 上传时间:2023-06-20
- 格式:DOCX
- 页数:26
- 大小:19.07KB
汽车管理系统的模拟全部代码.docx
《汽车管理系统的模拟全部代码.docx》由会员分享,可在线阅读,更多相关《汽车管理系统的模拟全部代码.docx(26页珍藏版)》请在冰豆网上搜索。
汽车管理系统的模拟全部代码
/*==============================================================*/
/*Databasename:
db_csms*/
/*DBMSname:
MicrosoftSQLServer2005*/
/*Createdon:
2014-7-269:
14:
46*/
/*==============================================================*/
dropdatabasedb_csms
go
/*==============================================================*/
/*Database:
db_csms*/
/*==============================================================*/
createdatabasedb_csms
go
usedb_csms
go
/*==============================================================*/
/*Table:
tb_car*/
/*==============================================================*/
createtabletb_car(
car_nochar(12)notnull,
wh_idintnotnull,
car_logovarchar(20)NOTnull,
car_typevarchar(20)NOTnull,
car_colorvarchar(20)NOTnull,
car_pricefloat(4)NOTnull,
car_datedatetimeNOTnull,
car_remarktextnull,
constraintPK_TB_CARprimarykeynonclustered(car_no),
CONSTRAINTFK_CAR_WHFOREIGNKEY(wh_id)REFERENCEStb_wh(wh_id)
)
go
/*==============================================================*/
/*Table:
tb_wh*/
/*==============================================================*/
createtabletb_wh(
wh_idintidentity,
wh_namevarchar(20)null,
wh_total_numintnull,
wh_addrvarchar(100)null,
wh_numintnull,
wh_remarktextnull,
constraintPK_TB_WHprimarykeynonclustered(wh_id)
)
go
package.softeem.jdbc.util;
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.sql.Statement;
publicclassDBUtil{
privatestaticfinalStringDRIVER=".microsoft.sqlserver.jdbc.SQLServerDriver";
privatestaticfinalStringUSER="sa";
privatestaticfinalStringPASSWORD="admin123";
privatestaticfinalStringURL="jdbc:
sqlserver:
//localhost:
1433;database=db_csms";
static{
try{
Class.forName(DRIVER);
}catch(ClassNotFoundExceptione){
e.printStackTrace();
}
}
publicstaticConnectiongetConn(){
Connectionconn=null;
try{
conn=DriverManager.getConnection(URL,USER,PASSWORD);
}catch(SQLExceptione){
e.printStackTrace();
}
returnconn;
}
publicstaticvoidclose(ResultSetrs,Statementst,Connectionconn){
try{
if(rs!
=null){
rs.close();
}
if(st!
=null){
st.close();
}
if(conn!
=null){
conn.close();
}
}catch(SQLExceptione){
e.printStackTrace();
}
}
}
package.softeem.jdbc.dto;
publicclassWareHouseDTO{
//仓库编号
privateintwhId;
//仓库名称
privateStringwhName;
//仓库总量
privateintwhTotalNum;
//仓库地址
privateStringwhAddr;
//仓库库存量
privateintwhNum;
//仓库备注
privateStringwhRemark;
//无参数的构造方法
publicWareHouseDTO(){
}
//全参数的构造方法
publicWareHouseDTO(intwhId,StringwhName,intwhTotalNum,StringwhAddr,
intwhNum,StringwhRemark){
this.whId=whId;
this.whName=whName;
this.whTotalNum=whTotalNum;
this.whAddr=whAddr;
this.whNum=whNum;
this.whRemark=whRemark;
}
//去掉id的构造方法
publicWareHouseDTO(StringwhName,intwhTotalNum,StringwhAddr,
intwhNum,StringwhRemark){
this.whName=whName;
this.whTotalNum=whTotalNum;
this.whAddr=whAddr;
this.whNum=whNum;
this.whRemark=whRemark;
}
//getter和setter方法
publicintgetWhId(){
returnwhId;
}
publicvoidsetWhId(intwhId){
this.whId=whId;
}
publicStringgetWhName(){
returnwhName;
}
publicvoidsetWhName(StringwhName){
this.whName=whName;
}
publicintgetWhTotalNum(){
returnwhTotalNum;
}
publicvoidsetWhTotalNum(intwhTotalNum){
this.whTotalNum=whTotalNum;
}
publicStringgetWhAddr(){
returnwhAddr;
}
publicvoidsetWhAddr(StringwhAddr){
this.whAddr=whAddr;
}
publicintgetWhNum(){
returnwhNum;
}
publicvoidsetWhNum(intwhNum){
this.whNum=whNum;
}
publicStringgetWhRemark(){
returnwhRemark;
}
publicvoidsetWhRemark(StringwhRemark){
this.whRemark=whRemark;
}
Override
publicStringtoString(){
returnthis.whId+"\t"+this.whName+"\t"+this.whTotalNum+"\t"
+this.whAddr+"\t"+this.whNum+"\t"+this.whRemark;
}
}
==================================================================================
package.softeem.jdbc.dto;
importjava.text.SimpleDateFormat;
importjava.util.Date;
publicclassCarDTO{
//车的编号
privateStringcarNo;
//利用对象建立关联,一个car对象可以找到对应的仓库信息,car和wh属于多对一的关系
privateWareHouseDTOwh;
//车的logo
privateStringcarLogo;
//车的类型
privateStringcarType;
//车的颜色
privateStringcarColor;
//车的价格
privatefloatcarPrice;
//车的日期
privateDatecarDate;
//车的备注
privateStringcarRemark;
//无参数的构造方法
publicCarDTO(){
}
//全参数的构造方法
publicCarDTO(StringcarNo,WareHouseDTOwh,StringcarLogo,
StringcarType,StringcarColor,floatcarPrice,DatecarDate,
StringcarRemark){
this.carNo=carNo;
this.wh=wh;
this.carLogo=carLogo;
this.carType=carType;
this.carColor=carColor;
this.carPrice=carPrice;
this.carDate=carDate;
this.carRemark=carRemark;
}
//getter和setter方法
publicStringgetCarNo(){
returncarNo;
}
publicvoidsetCarNo(StringcarNo){
this.carNo=carNo;
}
publicWareHouseDTOgetWh(){
returnwh;
}
publicvoidsetWh(WareHouseDTOwh){
this.wh=wh;
}
publicStringgetCarLogo(){
returncarLogo;
}
publicvoidsetCarLogo(StringcarLogo){
this.carLogo=carLogo;
}
publicStringgetCarType(){
returncarType;
}
publicvoidsetCarType(StringcarType){
this.carType=carType;
}
publicStringgetCarColor(){
returncarColor;
}
publicvoidsetCarColor(StringcarColor){
this.carColor=carColor;
}
publicfloatgetCarPrice(){
returncarPrice;
}
publicvoidsetCarPrice(floatcarPrice){
this.carPrice=carPrice;
}
publicDategetCarDate(){
returncarDate;
}
publicvoidsetCarDate(DatecarDate){
this.carDate=carDate;
}
publicStringgetCarRemark(){
returncarRemark;
}
publicvoidsetCarRemark(StringcarRemark){
this.carRemark=carRemark;
}
Override
publicStringtoString(){
Stringdate=newSimpleDateFormat("yyy-MM-dd").format(this.carDate);
returnthis.carNo+"\t"+this.carLogo+"\t"+this.carType+"\t"
+this.carColor+"\t"+this.carPrice+"\t"+date+"\t"
+wh.getWhId()+"\t"+wh.getWhName()+"\t"+wh.getWhAddr();
}
}
package.softeem.jdbc.dao;
importjava.sql.CallableStatement;
importjava.sql.Connection;
importjava.sql.PreparedStatement;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.sql.Statement;
importjava.util.ArrayList;
importjava.util.List;
import.softeem.jdbc.dto.WareHouseDTO;
import.softeem.jdbc.util.DBUtil;
/*
wh_idintidentity,
wh_namevarchar(20)null,
wh_total_numintnull,
wh_addrvarchar(100)null,
wh_numintnull,
wh_remarktextnull,
*/
publicclassWareHouseDAO{
privateConnectionconn;
privateStatementst;
privatePreparedStatementpst;
privateCallableStatementcst;
privateResultSetrs;
//插入一条记录,其中id是自动生成的
publicbooleaninsert(WareHouseDTOdto){
booleanflag=false;
Stringsql="insertintotb_wh(wh_name,wh_total_num,wh_addr,wh_num,wh_remark)"
+"values(?
?
?
?
?
)";
conn=DBUtil.getConn();
try{
pst=conn.prepareStatement(sql);
pst.setString(1,dto.getWhName());
pst.setInt(2,dto.getWhTotalNum());
pst.setString(3,dto.getWhAddr());
pst.setInt(4,dto.getWhNum());
pst.setString(5,dto.getWhRemark());
flag=pst.executeUpdate()>0?
true:
false;
}catch(SQLExceptione){
e.printStackTrace();
}finally{
DBUtil.close(null,pst,conn);
}
returnflag;
}
//删除一条记录,根据id删除的
publicbooleandelete(intid){
booleanflag=false;
Stringsql="deletefromtb_whwherewh_id=?
";
conn=DBUtil.getConn();
try{
pst=conn.prepareStatement(sql);
pst.setInt(1,id);
flag=pst.executeUpdate()>0?
true:
false;
}catch(SQLExceptione){
e.printStackTrace();
}finally{
DBUtil.close(null,pst,conn);
}
returnflag;
}
//更新一条记录,根据id更新其他的属性
publicbooleanupdate(WareHouseDTOdto){
booleanflag=false;
Stringsql="updatetb_whsetwh_name=?
wh_total_num=?
wh_addr=?
wh_num=?
wh_remark=?
)"
+"wherewh_id=?
";
conn=DBUtil.getConn();
try{
pst=conn.prepareStatement(sql);
pst.setString(1,dto.getWhName());
pst.setInt(2,dto.getWhTotalNum());
pst.setString(3,dto.getWhAddr());
pst.setInt(4,dto.getWhNum());
pst.setString(5,dto.getWhRemark());
pst.setInt(6,dto.getWhId());
flag=pst.executeUpdate()>0?
true:
false;
}catch(SQLExceptione){
e.printStackTrace();
}finally{
DBUtil.close(null,pst,conn);
}
returnflag;
}
//查询所有的记录
publicList
List
Stringsql="select*fromtb_wh";
conn=DBUtil.getConn();
try{
st=conn.createStatement();
rs=st.executeQuery(sql);
while(rs.next()){
intid=rs.getInt("wh_id");
Stringname=rs.getString("wh_name");
inttotalNum=rs.getInt("wh_total_num");
Stringaddr=rs.getString("wh_addr");
intnum=rs.getInt("wh_num");
Stringremark=rs.getString("wh_remark");
list.add(newWareHouseDTO(id,name,totalNum,addr,num,remark));
}
}catch(SQLExceptione){
e.printStackTrace();
}finally{
DBUtil.close(rs,st,conn);
}
returnlist;
}
//根据id查询一条记录
publicWareHouseDTOlistById(intwhid){
WareHouseDTOwh=null;
Stringsql="select*fromtb_whwherewh_id=?
";
conn=DBUtil.getConn();
try{
pst=conn.prepareStatement(sql);
pst.s
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 汽车 管理 系统 模拟 全部 代码