
修改商品
-
2023年3月17日发(作者:第七书包)java商品管理系统(增删改查)
此商品管理系统是在myeclipse控制台实现的商品增删改查操作,较为普通,不是web端项⽬的那种,只能作为平时的实验,如果是课程设
计的话应该制作web端那种。
项⽬建⽴了⼀个包为System2,其中有两个class⽂件,分别为和。
以下代码为的内容
packageSystem2;
tion;
Manager;
Set;
eption;
ent;
publicclassShopSystem{
publicvoidinsertShop(intid,Stringname,Stringintroduce){//插⼊
Connectionconn=null;
Statementstmt=null;
try{
e("");
conn=nection("jdbc:mysql://localhost:3306/test","root","111");
//创造SQL语句
Stringsql="INSERTINTOshop(id,name,introduce)VALUES('"+id+"','"+name+"','"+introduce+"')";
stmt=Statement();
eUpdate(sql);
}catch(Exceptione){
tackTrace();
}finally{
try{
();
}catch(SQLExceptione){
tackTrace();
}
try{
();
}catch(SQLExceptione){
tackTrace();
}
}
}
publicvoiddeleteShop(Stringname){//删除
Connectionconn=null;
Statementstmt=null;
try{
e("");
conn=nection("jdbc:mysql://localhost:3306/test","root","111");
Stringsql="DeleteFromshopwherename='"+name+"'";
stmt=Statement();
eUpdate(sql);
}catch(Exceptione){
tackTrace();
}finally{
try{
();
}catch(SQLExceptione){
tackTrace();
}
try{
();
();
}catch(SQLExceptione){
tackTrace();
}
}
}
publicvoidupdateShop(Stringname,Stringintroduce){//更新
Connectionconn=null;
Statementstmt=null;
try{
e("");
conn=nection("jdbc:mysql://localhost:3306/test","root","111");
Stringsql="UPDATEshopSETintroduce='"+introduce+"'"+"WHEREname='"+name+"'";
stmt=Statement();
eUpdate(sql);
}catch(Exceptione){
tackTrace();
}finally{
try{
();
}catch(SQLExceptione){
tackTrace();
}
try{
();
}catch(SQLExceptione){
tackTrace();
}
}
}
publicvoidsearchAllShop(){//输出全部信息
Connectionconn=null;
Statementstmt=null;
ResultSetrs=null;
try{
e("");
conn=nection("jdbc:mysql://localhost:3306/test","root","111");
Stringsql="SELECT*FROMshop";
stmt=Statement();
rs=eQuery(sql);
while(()){
intid=(1);
Stringname=ing(2);
Stringintroduce=ing(3);
n(id+"-"+name+"-"+introduce);
}
}catch(Exceptione){
tackTrace();
}finally{
try{
();
}catch(SQLExceptione1){
tackTrace();
}
try{
();
}catch(SQLExceptione){
tackTrace();
}
try{
();
}catch(SQLExceptione){
tackTrace();
}
}
}
}
conn=nection("jdbc:mysql://localhost:3306/test","root","111");
//test是mysql⾥⾯创建的数据库,root是⽤户名,111是密码
Stringsql="INSERTINTOshop(id,name,introduce)VALUES('"+id+"','"+name+"','"+introduce+"')";
//shop是test数据库⾥的表,包含id,name,introduce三个字段。
以下代码是⾥⾯的内容:
packageSystem2;
r;
publicclassTest{
publicstaticvoidmain(Stringargs[]){
ShopSystemss=newShopSystem();
intid;
Stringname=null;
Stringintroduce=null;
n("-----商品管理系统-----");
n("--物联⽹194吴铭世制作--");
while(true){
n("(1)添加商品信息");
n("(2)修改商品信息");
n("(3)删除商品信息");
n("(4)显⽰全部商品信息");
n("(5)退出");
n("请输⼊相应数字选择相应操作");
Scannerscanner=newScanner();
intkey=t();
switch(key){
case1:
n("新增数据:");
n("输⼊id:");
id=t();
//n(id);
n("输⼊name:");
ne();
name=ne();
//n(name);
n("输⼊introduce:");
//ne();
introduce=ne();
//n(introduce);
Shop(id,name,introduce);
n("增加商品成功!n");
n("增加商品成功!n");
break;
case2:
n("修改信息:");
n("输⼊name:");
ne();
name=ne();
n("输⼊introduce:");
//ne();
introduce=ne();
Shop(name,introduce);
n("修改成功!n");
break;
case3:
n("删除商品:");
n("输⼊name:");
ne();
name=ne();
Shop(name);
n("删除成功!n");
break;
case4:
n("显⽰全部商品信息:");
AllShop();
//ne();
n("n");
break;
case5:
n("成功退出!n");
return;
default:
n("请输⼊1-5选择相应操作!!n");
break;
}
}
}
}
两个java⽂件创建完,数据库连接成功,运⾏⽂件就可以在控制台测试了,具体运⾏情况如下:
好好打代码,别偷懒哦
尽快找好主修⽅向(最晚⼤三开学时),前端、软件、单⽚机、嵌⼊式……精通其中⼀个才好找⼯作。
希望能帮到你们,别忘了点个赞哦。
2021.11.22