用java做的一个图书管理系统的源代码.docx
- 文档编号:12516362
- 上传时间:2023-04-19
- 格式:DOCX
- 页数:57
- 大小:22.75KB
用java做的一个图书管理系统的源代码.docx
《用java做的一个图书管理系统的源代码.docx》由会员分享,可在线阅读,更多相关《用java做的一个图书管理系统的源代码.docx(57页珍藏版)》请在冰豆网上搜索。
用java做的一个图书管理系统的源代码
用java做的一个图书管理系统的源代码
importjava.sql.*;
importjava.util.*;
publicclassT{
publicstaticvoidmain(String[]args)throwsException{
Connectionconn=null;
Statementstmt=null;
ResultSetrs=null;
while(true)
{Scannerscanner=newScanner(System.in);
System.out.println("请输入用户名:
");
Stringusername2=scanner.next();
System.out.println("请输入密码:
");
Stringpassword2=scanner.next();
if(!
(username2.equals("")||password2.equals(""))){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:
odbc:
book","","");
Stringsql="select*fromwwwhereusername='"+username2+"'";
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
if(rs.next())
{
if(rs.getString("password").equals(password2))
{
System.out.println("*********欢迎来山东科技大学图书馆管理系统********");
while(true)
{
System.out.println("1.图书信息");
System.out.println("2.读者信息");
System.out.println("3.管理员信息");
System.out.println("4.借阅信息");
System.out.println("5.还书信息");
System.out.println("6.逾期罚款或损坏赔偿信息");
//System.out.println("7.退出");
System.out.println("请输入选择功能的序号:
");
inta=scanner.nextInt();
switch(a){
case1:
System.out.println("图书信息:
");
System.out.println("1.查询图书信息:
");
System.out.println("2.插入图书信息:
");
System.out.println("3.删除图书信息:
");
System.out.println("4.修改图书信息:
");
inta1=scanner.nextInt();
switch(a1)
{
case1:
System.out.println("欢迎进入图书信息查询系统:
");
System.out.println("1.无条件查询图书信息:
");
System.out.println("2.条件查询图书信息:
");
intd=scanner.nextInt();
switch(d){
case1:
intllll=0;
//intmm=0;
while(llll!
=1){
System.out.println("1.无条件查询图书信息:
");
StringSql0="SELECT*FROMsystembook";
rs=stmt.executeQuery(Sql0);
while(rs.next()){
StringbookID=rs.getString
(1);
StringbookNo=rs.getString
(2);
StringbookName=rs.getString(3);
StringbookWriter=rs.getString(4);
StringbookPub=rs.getString(5);
System.out.println(bookID+","+bookNo+","+bookName+","+bookWriter+","+bookPub);
}
System.out.println("是否继续插入?
yes/nono返回主菜单");
Stringk=scanner.next();
if(k.startsWith("yes"))
{
System.out.println();
};
if(k.startsWith("no"))
{
llll=1;
System.out.println();
};
}
break;
//break;
case2:
System.out.println("2.条件查询图书信息:
");
System.out.println("1.单条件查询图书信息:
");
System.out.println("2.模糊条件查询图书信息:
");
System.out.println("3.多表连接查询图书信息:
");
System.out.println("4.嵌套查询图书信息:
");
System.out.println("5.谓词演算查询");
intc12=scanner.nextInt();
switch(c12){
case1:
System.out.println("1.单条件查询:
");
System.out.println("1.按图书名编码号查询图书信息:
");
intddd=0;
while(ddd!
=1){
System.out.println("请输入图书编码号:
");
StringA=scanner.next();
Stringsql1="SELECT*FROMsystembookWHEREbookID='"+A+"'";
rs=stmt.executeQuery(sql1);
intx=0;
while(rs.next())
{
Stringa2=rs.getString
(1);
Stringb2=rs.getString
(2);
Stringc2=rs.getString(3);
Stringd2=rs.getString(4);
Stringe2=rs.getString(5);
System.out.println(a2+","+b2+","+c2+","+d2+","+e2);
x++;
}
if(x==0)
{System.out.println("查无此书,请重新输入");
}
else{
System.out.println("是否继续按姓名查询?
yes/nono返回主菜单");
Stringk=scanner.next();
if(k.startsWith("yes"))
{
System.out.println();
};
if(k.startsWith("no"))
{
ddd=1;
System.out.println();
};
};
}
break;
case2:
System.out.println("2.模糊查询图书信息:
");
intdc=0;
while(dc!
=1){
System.out.println("请用户输入图书名字中的模糊关键字");
StringE=scanner.next();
Stringsq123="SELECT*FROMsystembookWHEREbookNameLIKE'"+E+"%'";
rs=stmt.executeQuery(sq123);
intz=0;
while(rs.next())
{
Stringa2=rs.getString
(1);
Stringb2=rs.getString
(2);
Stringc2=rs.getString(3);
Stringd2=rs.getString(4);
Stringe2=rs.getString(5);
System.out.println(a2+","+b2+","+c2+","+d2+","+e2);
z++;
}
if(z==0)
{System.out.println("查无此书,请重新输入");
}
else{
System.out.println("是否继续输入图书名字中的模糊关键字?
yes/nono返回主菜单");
Stringk=scanner.next();
if(k.startsWith("yes"))
{
System.out.println();
};
if(k.startsWith("no"))
{
dc=1;
System.out.println();
//break;
};
}
}
break;
case3:
System.out.println("3.多表连接查询查询图书信息:
");
intdq=0;
while(dq!
=1){
System.out.println("查询逾期罚款或是赔偿表中的读者的相关信息");
System.out.println("请输入逾期罚款或是赔偿的读者编码号");
StringF=scanner.next();
Stringsq1234="SELECT*FROMfine,borrowbook,systemreaderWHEREfine.bookID=borrowbook.bookIDANDborrowbook.reaID=systemreader.reaIDANDfine.bookID='"+F+"'";
rs=stmt.executeQuery(sq1234);
intn=0;
while(rs.next())
{
Stringa2=rs.getString
(1);
Stringb2=rs.getString
(2);
Stringc2=rs.getString(3);
Stringd2=rs.getString(4);
Stringe2=rs.getString(5);
System.out.println(a2+","+b2+","+c2+","+d2+","+e2);
n++;
}
if(n==0)
{System.out.println("查无此人,请重新输入");
}
else
{
System.out.println("是否继续输入图书名字中的模糊关键字?
yes/nono返回主菜单");
Stringk=scanner.next();
if(k.startsWith("yes"))
{
System.out.println();
};
if(k.startsWith("no"))
{
ddd=1;
System.out.println();
};
}
}
break;
case4:
System.out.println("4.嵌套查询图书信息:
");
intdq1=0;
while(dq1!
=1){
System.out.println("查询某读者所在年级女读者的相关信息");
System.out.println("请输入某读者的读者编号");
StringG=scanner.next();
Stringsq12345="SELECT*FROMsystemreaderWHEREreaGrade=(SELECTreaGradeFROMsystemreaderWHEREreaID='"+G+"')ANDreasex='女'";
rs=stmt.executeQuery(sq12345);
intm=0;
while(rs.next())
{
Stringa2=rs.getString
(1);
Stringb2=rs.getString
(2);
Stringc2=rs.getString(3);
Stringd2=rs.getString(4);
Stringe2=rs.getString(5);
System.out.println(a2+","+b2+","+c2+","+d2+","+e2);
m++;
}
if(m==0)
{System.out.println("查无此书,请重新输入");
}
else
{
System.out.println("是否继续输入读者编号?
yes/nono返回主菜单");
Stringk=scanner.next();
if(k.startsWith("yes"))
{
System.out.println();
};
if(k.startsWith("no"))
{
d=1;
System.out.println();
};
}
}
break;
case5:
System.out.println("5.谓词演算查询:
");
intdq1123=0;
while(dq1123!
=1)
{
System.out.println("查询借阅了某本书的读者的相关信息");
System.out.println("请输入该书的名字");
StringH=scanner.next();
Stringsq123456="SELECT*FROMsystemreaderWHEREreaIDIN(SELECTreaIDFROMborrowbookWHEREbookName='"+H+"')";
rs=stmt.executeQuery(sq123456);
intl=0;
while(rs.next())
{
Stringa2=rs.getString
(1);
Stringb2=rs.getString
(2);
Stringc2=rs.getString(3);
Stringd2=rs.getString(4);
Stringe2=rs.getString(5);
System.out.println(a2+","+b2+","+c2+","+d2+","+e2);
l++;
}
if(l==0)
{
System.out.println("查无此人,请重新输入");
}
else
{
System.out.println("是否继续输入图书名字?
yes/nono返回主菜单");
Stringk=scanner.next();
if(k.startsWith("yes"))
{
System.out.println();
};
if(k.startsWith("no"))
{
d=1;
System.out.println();
};
}
}
break;
}//c12
break;
}
break;
/*case1:
System.out.println("1.查询图书信息:
");
StringSql="SELECT*FROMsystembook";
rs=stmt.executeQuery(Sql);
while(rs.next()){
//Stringstr=scanner.next();
StringbookID=rs.getString
(1);
StringbookNo=rs.getString
(2);
StringbookName=rs.getString(3);
StringbookWriter=rs.getString(4);
StringbookPub=rs.getString(5);
System.out.println(bookID+","+bookNo+","+bookName+","+bookWriter+","+bookPub);
}
break;*/
case2:
intzz=0;
while(zz!
=1){
System.out.println("2.插入图书信息:
");
System.out.println("请按顺序插入图书条码号,图书索书号,图书名字,图书作者,图书出版社");
Stringstr=scanner.next();
String[]splitst=str.split(",");
Stringa11=splitst[0];
Stringa12=splitst[1];
Stringa13=splitst[2];
Stringa14=splitst[3];
Stringa15=splitst[4];
StringinsertSql="INSERTINTOsystembook(bookID,bookNo,bookName,bookWriter,bookPub)VALUES('"+a11+"','"+a12+"','"+a13+"','"+a14+"','"+a15+"')";
inti=stmt.executeUpdate(insertSql);//返回记录影响的条数
if(i!
=0){
System.out.println("插入成功!
");}
System.out.println("是否继续插入?
yes/nono返回主菜单");
Stringk=scanner.next();
if(k.startsWith("yes"))
{
System.out.println();
};
if(k.startsWith("no"))
{
zz=1;
System.out.println();
};
}
break;
case3:
intll=0;
//intmm=0;
while(ll!
=1){
System.out.println("3.删除图书信息:
");
System.out.println("请输入要删除的图书编号:
");
StringStr=scanner.next();
String[]Splitst=Str.split(",");
Stringb3=Splitst[0];
Stringsql1="SELECT*FROMsystembookwherebookID='"+b3+"'";
rs=stmt.executeQuery(sql1);
intkkk=0;
while(rs.next())
{
Stringa22=rs.getString
(1);
Stringb22=rs.getString
(2);
Stringc22=rs.getString(3);
Stringd22=rs.getString(4);
Stringe22=rs.getString(5);
Stringf22=rs.getString(6);
System.out.println(a22+","+b22+","+c22+","+d22+","+e22+","+f22);
kkk++;
}
if(kkk==0)
{
System.out.println("没有这本书,请重新输入");
}
else
{
{StringdeleSql="DELETEFROMsystembookWHEREbookID='"+b3+"'";
intp=stmt.executeUpdate(deleSql);//返回记录影响的条数
if(p!
=0){
System.out.println("删除成功!
");
}
System.out.println("是否继续删除?
yes/nono返回主菜单");
Stringl=scanner.next();
if(l.startsWith("yes"))
{
System.out.println();
};
if(l.startsWith("no"))
{
ll=1;
System.out.println();
};
};
}
}
break;
case4:
intmm=0;
while(mm!
=1){
System.out.println("4.修改图书信息:
");
System.out.println("请输入修改的图书ID");
StringS=scanner.next();
Stringsql1="SELECT*FROMsystem
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java 一个 图书 管理 系统 源代码
![提示](https://static.bdocx.com/images/bang_tan.gif)