代码
package library;
import java.sql.*;
import java.util.*;
public class T{
public static void main(String[] args) throws Exception{
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
while(true)
{Scanner scanner=new Scanner(System.in);
System.out.println("请输入用户名");
String username=scanner.next();
System.out.println("请输入密码");
String password=scanner.next();
if(!(username.equals("")||password.equals(""))){
try{
Class.forName("com.mysql.jdbc.Driver");
String url=”jdbc:mysql://localhost:3306/book”;
conn=DriverManager.getConnection("url","username","password");
String sql="select * from gl where username1='"+username+"'";
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
if(rs.next())
{
if(rs.getString("password").equals(password1))
{
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(" 请输入选择功能的序号 :");
int a=scanner.nextInt();
switch(a){
case 1:
System.out.println(" 图书信息: ");
System.out.println(" 1. 查询图书信息: ");
System.out.println(" 2. 插入图书信息: ");
System.out.println(" 3. 删除图书信息: ");
System.out.println(" 4. 修改图书信息: ");
int a1=scanner.nextInt();
switch(a1)
{
case 1:
System.out.println(" 欢迎进入图书信息查询系统: ");
System.out.println(" 1. 无条件查询图书信息: ");
System.out.println(" 2. 条件查询图书信息: ");
int d=scanner.nextInt();
switch(d){
case 1:
int llll=0;
int mm=0;
while(llll!=1){
System.out.println(" 1. 无条件查询图书信息: ");
String Sql0 = "SELECT * FROM systembook ";
rs= stmt.executeQuery(Sql0);
while(rs.next()){
String bookID =rs.getString(1);
String bookNo =rs.getString(2);
String bookName =rs.getString(3);
String bookWriter =rs.getString(4);
String bookPub =rs.getString(5);
System.out.println(bookID+","+bookNo+","+bookName+","+bookWriter+","+bookPub);
}
System.out.println("是否继续插入yes/no no返回主菜单");
String k=scanner.next();
if(k.startsWith("yes"))
{
System.out.println();
};
if(k.startsWith("no"))
{
llll=1;
System.out.println();
};
}
break;
}
case 2:
System.out.println(" 2. 条件查询图书信息: ");
System.out.println(" 1. 单条件查询图书信息: ");
System.out.println(" 2. 模糊条件查询图书信息: ");
System.out.println(" 3. 多表连接查询图书信息: ");
System.out.println(" 4. 嵌套查询图书信息: ");
System.out.println(" 5. 谓词演算查询 ");
int c12=scanner.nextInt();
switch(c12){
case 1:
System.out.println(" 1.单条件查询: ");
System.out.println(" 1.按图书名编码号查询图书信息: ");
int ddd=0;
while(ddd!=1){
System.out.println("请输入图书编码号:");
String A=scanner.next();
String sql1= "SELECT * FROM systembook WHERE bookID ='"+A+"' ";
rs= stmt.executeQuery(sql1);
int x=0;
while(rs.next())
{
String a2 =rs.getString(1); String b2 =rs.getString(2);
String c2 =rs.getString(3);
String d2 =rs.getString(4);
String e2 =rs.getString(5);
System.out.println(a2+","+b2+" ,"+c2+","+d2+","+e2);
x++;
}
if(x==0)
{System.out.println("查无此书,请重新输入");
}
else{
System.out.println("是否继续按姓名查询yes/no no返回主菜单");
String k=scanner.next();
if(k.startsWith("yes"))
{
System.out.println();
};
if(k.startsWith("no"))
{
ddd=1;
System.out.println();
};
};
}
break;
}
case 2:
System.out.println(" 2.模糊查询图书信息: ");
int dc=0;
while(dc!=1){
System.out.println("请用户输入图书名字中的模糊关键字");
String E=scanner.next();
String sq123= "SELECT * FROM systembook WHERE bookName LIKE'"+E+"%'";
rs= stmt.executeQuery(sq123);
int z=0;
while(rs.next())
{
String a2 =rs.getString(1);
String b2 =rs.getString(2);
String c2 =rs.getString(3);
String d2 =rs.getString(4);
String e2 =rs.getString(5);
System.out.println(a2+","+b2+" ,"+c2+","+d2+","+e2);
z++;
}
if(z==0)
{System.out.println("查无此书,请重新输入");
}
else{
System.out.println("是否继续输入图书名字中的模糊关键字yes/no no返回主菜单");
String k=scanner.next();
if(k.startsWith("yes"))
{
System.out.println();
};
if(k.startsWith("no"))
{
dc=1;
System.out.println();
break;
};
}
}
break;
}
case 3:
System.out.println(" 3.多表连接查询查询图书信息: ");
int dq=0;
while(dq!=1){
System.out.println("查询逾期罚款或是赔偿表中的读者的相关信息");
System.out.println("请输入逾期罚款或是赔偿的读者编码号");
String F=scanner.next();
String sq1234= "SELECT * FROM fine,borrowbook,systemreader WHERE fine.bookID=borrowbook.bookID AND borrowbook.reaID=systemreader.reaID AND fine.bookID='"+F+"' ";
rs= stmt.executeQuery(sq1234);
int n=0;
while(rs.next())
{
String a2 =rs.getString(1);
String b2 =rs.getString(2);
String c2 =rs.getString(3);
String d2 =rs.getString(4);
String e2 =rs.getString(5);
System.out.println(a2+","+b2+" ,"+c2+","+d2+","+e2);
n++;
}
if(n==0)
{System.out.println("查无此人,请重新输入");
}
else
{
System.out.println("是否继续输入图书名字中的模糊关键字yes/no no返回主菜单");
String k=scanner.next();
if(k.startsWith("yes"))
{
System.out.println();
};
if(k.startsWith("no"))
{
ddd=1;
System.out.println();
};
}
}
break;
}
case 4:
System.out.println(" 4.嵌套查询图书信息: ");
int dq1=0;
while(dq1!=1){
System.out.println("查询某读者所在年级女读者的相关信息");
System.out.println("请输入某读者的读者编号");
String G=scanner.next();
String sq12345= "SELECT * FROM systemreader WHERE reaGrade=(SELECT reaGrade FROM systemreader WHERE reaID='"+G+"') AND reasex='女'";
rs= stmt.executeQuery(sq12345);
int m=0;
while(rs.next())
{
String a2 =rs.getString(1);
String b2 =rs.getString(2);
String c2 =rs.getString(3);
String d2 =rs.getString(4);
String e2 =rs.getString(5);
System.out.println(a2+","+b2+" ,"+c2+","+d2+","+e2);
m++;
}
if(m==0)
{System.out.println("查无此书,请重新输入");
}
else
{
System.out.println("是否继续输入读者编号yes/no no返回主菜单");
String k=scanner.next();
if(k.startsWith("yes"))
{
System.out.println();
};
if(k.startsWith("no"))
{
d=1;
System.out.println();
};
}
}
break;
}
case 5:
System.out.println(" 5. 谓词演算查询 ");
int dq1123=0;
while(dq1123!=1)
{
System.out.println("查询借阅了某本书的读者的相关信息");
System.out.println("请输入该书的名字");
String H=scanner.next();
String sq123456= "SELECT * FROM systemreader WHERE reaID IN (SELECT reaID FROM borrowbook WHERE bookName='"+H+"')";
rs= stmt.executeQuery(sq123456);
int l=0;
while(rs.next())
{
String a2 =rs.getString(1);
String b2 =rs.getString(2);
String c2 =rs.getString(3);
String d2 =rs.getString(4);
String e2 =rs.getString(5);
System.out.println(a2+","+b2+" ,"+c2+","+d2+","+e2);
l++;
}
if(l==0)
{
System.out.println("查无此人,请重新输入");
}
else
{
System.out.println("是否继续输入图书名字yes/no no返回主菜单");
String k=scanner.next();
if(k.startsWith("yes"))
{
System.out.println();
};
if(k.startsWith("no"))
{
d=1;
System.out.println();
};
}
}
break;
}
break;
}
break;
case 1:
System.out.println(" 1. 查询图书信息: ");
String Sql = "SELECT * FROM systembook ";
rs= stmt.executeQuery(Sql);
while(rs.next()){
String str =scanner.next();
String bookID =rs.getString(1);
String bookNo =rs.getString(2);
String bookName =rs.getString(3);
String bookWriter =rs.getString(4);
String bookPub =rs.getString(5);
System.out.println(bookID+","+bookNo+","+bookName+","+
bookWriter+","+bookPub);
}
break;
}
case 2:
int zz=0;
while(zz!=1){
System.out.println(" 2. 插入图书信息: ");
System.out.println("请按顺序插入图书条码号,图书索书号,图书名字,图书作者,图书出版社");
String str=scanner.next();
String []splitst=str.split(",");
String a11=splitst[0];
String a12=splitst[1];
String a13=splitst[2];
String a14=splitst[3];
String a15=splitst[4];
String insertSql="INSERT INTO systembook(bookID,bookNo,bookName,bookWriter,bookPub) VALUES('"+a11+"','"+a12+"','"+a13+"','"+a14+"','"+a15+"')";
int i=stmt.executeUpdate(insertSql); //返回记录影响的条数
if(i!=0){
System.out.println("插入成功!"); }
System.out.println("是否继续插入yes/no no返回主菜单");
String k=scanner.next();
if(k.startsWith("yes"))
{
System.out.println();
};
if(k.startsWith("no"))
{
zz=1;
System.out.println();
};
}
break;
}
case 3:
int ll=0;
int mm=0;
while(ll!=1){
System.out.println(" 3. 删除图书信息: ");
System.out.println("请输入要删除的图书编号:");
String Str=scanner.next();
String []Splitst=Str.split(",");
String b3=Splitst[0];
String sql1="SELECT * FROM systembook where bookID='"+b3+"'";
rs= stmt.executeQuery(sql1);
int kkk=0;
while(rs.next())
{
String a22 =rs.getString(1);
String b22 =rs.getString(2);
String c22 =rs.getString(3);
String d22 =rs.getString(4);
String e22 =rs.getString(5);
String f22 =rs.getString(6);
System.out.println(a22+","+b22+" ,"+c22+","+d22+","+e22+","+f22);
kkk++;
}
if(kkk==0)
{
System.out.println( "没有这本书请重新输入");
}
else
{
{String deleSql= "DELETE FROM systembook WHERE bookID='"+b3+"'";
int p=stmt.executeUpdate(deleSql); //返回记录影响的条数
if(p!=0){
System.out.println("删除成功!");
}
System.out.println("是否继续删除yes/no no返回主菜单");
String l=scanner.next();
if(l.startsWith("yes"))
{
System.out.println();
}; if(l.startsWith("no"))
{
ll=1;
System.out.println();
};
};
}
}
break;}
case 4:
int mm=0;
while(mm!=1){
System.out.println(" 4. 修改图书信息: ");
System.out.println("请输入修改的图书ID ");
String S=scanner.next();
String sql1="SELECT * FROM systembook where bookID='"+S+"'";
rs= stmt.executeQuery(sql1);
int lll=0;
while(rs.next())
{
String a222 =rs.getString(1);
String b222 =rs.getString(2);
String c222 =rs.getString(3);
String d222 =rs.getString(4);
String e222 =rs.getString(5);
String f222 =rs.getString(6);
System.out.println(a222+","+b222+" ,"+c222+","+d222+","+e222+","+f222);
lll++;
}
if(lll==0)
{
System.out.println( "没有这本书请重新输入");
}
else
{
System.out.println("要将书名改为");
String bbb=scanner.next();
String updateSql1="UPDATE systembook SET bookName='"+bbb+"' WHERE bookID='"+S+"'";
int hh=stmt.executeUpdate(updateSql1); //返回记录影响的条数
if(hh!=0)
{
System.out.println("修改成功!");
}
System.out.println("是否继续修改yes/no no返回主菜单");
String o=scanner.next();
if(o.startsWith("yes"))
{
System.out.println();
};
if(o.startsWith("no"))
{
mm=1;
System.out.println();
};
}
}
break;
}
break;}
String updateSql="UPDATE systembook SET bookCopy='"+c1+"'WHERE bookName='数据库管理'";
int t=stmt.executeUpdate(updateSql); //返回记录影响的条数
if(t!=0){ System.out.println("修改成功!");}
break;
}break;}
case 2:
System.out.println(" 读者信息: ");
System.out.println(" 1. 查询读者信息: ");
System.out.println(" 2. 插入读者信息: ");
System.out.println(" 3. 删除读者信息: ");
System.out.println(" 4. 修改读者信息: " );
int b1=scanner.nextInt();
switch(b1){
case 1:
System.out.println(" 1. 查询读者信息: ");
String ssql = "SELECT * FROM systemreader ";
rs= stmt.executeQuery(ssql);
while(rs.next()){
String str =scanner.next();
String reaID=rs.getString(1);
String reaName =rs.getString(2);
String reaLBID =rs.getString(3);
String reaNo =rs.getString(4);
String reaSex =rs.getString(5);
String reaType =rs.getString(6);
String reaDep =rs.getString(7);
String reaGrade =rs.getString(8);
String reaPre =rs.getString(9);
String reaDate =rs.getString(10);
System.out.println(reaID+","+reaName+","+reaNo+","+reaSex+","+reaLBID+","+reaType+","+reaDep+","+reaGrade+","+reaPre+","+reaDate);
}
break;}
case 2:
int zz=0;
while(zz!=1){
System.out.println(" 2. 插入读者信息: ");
System.out.println("请按顺序插入 借书卡证号 读者名字 读者学号 读者性别 读者LBID 读者类型 读者学院 读者年级 读者专业 办证日期");
String str=scanner.next();
String []splitst=str.split(",");
String b11=splitst[0];
String b12=splitst[1];
String b13=splitst[2];
String b14=splitst[3];
String b15=splitst[4];
String b16=splitst[5];
String b17=splitst[6];
String b18=splitst[7];
String b19=splitst[8];
String b20=splitst[9];
String insertSql="INSERT INTO systemreader(reaID,reaName,reaNo,reaSex,reaLBID,reaType,reaDep,reaGrade,reaPre,reaDate) VALUES('"+b11+"','"+b12+"','"+b13+"','"+b14+"','"+b15+"','"+b16+"','"+b17+"','"+b18+"','"+b19+"','"+b20+"')";
int n=stmt.executeUpdate(insertSql); //返回记录影响的条数
if(n!=0){
System.out.println("插入成功!"); }
System.out.println("是否继续插入yes/no no返回主菜单");
String k=scanner.next();
if(k.startsWith("yes"))
{
System.out.println();
};
if(k.startsWith("no"))
{
zz=1;
System.out.println();
};
}
break;}
case 3:
int ll=0;
while(ll!=1){
System.out.println(" 3. 删除读者信息: "); System.out.println("请输入要删除的读者证号:");
String Str=scanner.next();
String []Splitst=Str.split(",");
String r=Splitst[0];
String sql1="SELECT * FROM systemreader where reaID='"+r+"'";
rs= stmt.executeQuery(sql1);
int kkk=0;
while(rs.next())
{
String a22 =rs.getString(1);
String b22 =rs.getString(2);
String c22 =rs.getString(3);
String d22 =rs.getString(4);
String e22 =rs.getString(5);
String f22 =rs.getString(6);
String g22 =rs.getString(7);
String h22 =rs.getString(8);
String i22 =rs.getString(9);
System.out.println(a22+","+b22+" ,"+c22+","+d22+","+e22+","+f22+","+g22+","+h22+","+i22);
kkk++;
}
if(kkk==0)
{
System.out.println( "没有这个读者请重新输入");
}
else
{
System.out.println( "您是否真的要删除? yes/no");
String k=scanner.next();
if(k.startsWith("y"))
{String deleSql= "DELETE FROM systemreader WHERE reaID='"+r+"'";
int p=stmt.executeUpdate(deleSql); //返回记录影响的条数
if(p!=0){
System.out.println("删除成功!");
}
System.out.println("是否继续删除yes/no no返回主菜单");
String l=scanner.next();
if(l.startsWith("yes"))
{
System.out.println();
};
if(l.startsWith("no"))
{
ll=1;
System.out.println();
};
};
}
}
String deleSql= "DELETE FROM systemreader WHERE
reaID='"+r+"'";
int m=stmt.executeUpdate(deleSql); //返回记录影响的条数
if(m!=0){
System.out.println("删除成功!");}
break;
}
case 4:
int mm=0;
while(mm!=1){
System.out.println(" 4. 修改读者信息: ");
System.out.println("请输入修改以后的读者的ID ");
String S=scanner.next();
// String []Ssplitst=S.split(",");
//String tt=Ssplitst[0];
String sql1="SELECT * FROM systemreader where reaID='"+S+"'";
rs= stmt.executeQuery(sql1);
int lll=0;
while(rs.next())
{
String a222 =rs.getString(1);
String b222 =rs.getString(2);
String c222 =rs.getString(3);
String d222=rs.getString(4);
String e222 =rs.getString(5);
String f222 =rs.getString(6);
String g222 =rs.getString(7);
String h222 =rs.getString(8);
String i222 =rs.getString(9);
String j222 =rs.getString(10);
System.out.println(a222+","+b222+" ,"+c222+","+d222+","+e222+","+f222+","+g222+","+h222+","+i222+","+j222);
lll++;
}
if(lll==0)
{
System.out.println( "没有这个人请重新输入");
}
else
{
System.out.println("要将名字改为");
String bb=scanner.next();
String updateSql="UPDATE systemreader SET reaName='"+bb+"' WHERE reaID='"+S+"'";
int hh=stmt.executeUpdate(updateSql); //返回记录影响的条数
if(hh!=0)
{
System.out.println("修改成功!");
}
System.out.println("是否继续修改yes/no no返回主菜单");
String o=scanner.next();
if(o.startsWith("yes"))
{
System.out.println();
};
if(o.startsWith("no"))
{
mm=1;
System.out.println();
};
}
}
break;}
String updateSql="UPDATE systemreader SET reaSex='"+tt+"' WHERE reaID='20030101'";
int l=stmt.executeUpdate(updateSql); //返回记录影响的条数
if(l!=0){
System.out.println("修改成功!");}
break;
}
}
break;
}
case 3:
System.out.println(" 管理员信息: ");
System.out.println(" 1. 查询管理员信息: ");
System.out.println(" 2. 插入管理员信息: ");
System.out.println(" 3. 删除管理员信息: ");
System.out.println(" 4. 修改管理员信息: ");
System.out.println(" 5. 返回上一级 ");
int c11=scanner.nextInt();
switch(c11){
case 1:
System.out.println(" 1. 查询管理员信息: ");
String Ssql = "SELECT * FROM manager ";
rs= stmt.executeQuery(Ssql);
while(rs.next()){
String str =scanner.next();
String mID =rs.getString(1);
String mName=rs.getString(2);
String mSex =rs.getString(3);
System.out.println(mID+","+mName+","+mSex);
}
break;
}
case 2:
int zz=0;
while(zz!=1){
System.out.println(" 2. 插入管理员信息: ");
System.out.println("请按顺序插入管理员的编号管理员的姓名,管理员的性别,所管书库电话地址");
String str=scanner.next();
String []splitst=str.split(",");
String a11=splitst[0];
String a12=splitst[1];
String a13=splitst[2];
String a14=splitst[3];
String a15=splitst[4];
String a16=splitst[5];
String insertSql="INSERT INTO manager(mID,mName,mSex,mAuth,mTeleph,mAddre) VALUES('"+a11+"','"+a12+"','"+a13+"','"+a14+"','"+a15+"','"+a16+"')";
int i=stmt.executeUpdate(insertSql); //返回记录影响的条数
if(i!=0){
System.out.println("插入成功!");
}
System.out.println("是否继续插入yes/no no返回主菜单");
String k=scanner.next();
if(k.startsWith("yes"))
{
System.out.println();
};
if(k.startsWith("no"))
{
zz=1;
System.out.println();
};
}
break;
}
case 3:
int ll=0;
while(ll!=1){
System.out.println(" 3. 删除管理员信息: ");
System.out.println("请输入要删除的管理员编号:");
String Str=scanner.next();
String []Splitst=Str.split(",");
String b3=Splitst[0];
String sql1="SELECT * FROM manager where mID='"+b3+"'";
rs= stmt.executeQuery(sql1);
int kkk=0;
while(rs.next())
{
String a22 =rs.getString(1);
String b22 =rs.getString(2);
String c22 =rs.getString(3);
String d22 =rs.getString(4);
String e22 =rs.getString(5);
String f22 =rs.getString(6);
System.out.println(a22+","+b22+" ,"+c22+","+d22+","+e22+","+f22);
kkk++;
}
if(kkk==0)
{
System.out.println( "没有这个管理员请重新输入");
}
else
{
System.out.println( "您是否真的要删除? yes/no");
String k=scanner.next();
if(k.startsWith("y"))
{String deleSql= "DELETE FROM manager WHERE mID='"+b3+"'";
int p=stmt.executeUpdate(deleSql); //返回记录影响的条数
if(p!=0){
System.out.println("删除成功!");
}
System.out.println("是否继续删除yes/no no返回主菜单");
String l=scanner.next(); if(l.startsWith("yes"))
{
System.out.println();
};
if(l.startsWith("no"))
{
ll=1;
System.out.println();
};
};
}
}
String deleSql= "DELETE mID FROM manager WHERE mID='"+b3+"'";
int k=stmt.executeUpdate(deleSql); //返回记录影响的条数
if(k!=0){
System.out.println("删除成功!");
}
break;
}
case 4:
int mm=0;
while(mm!=1){
System.out.println(" 4. 修改管理员信息: ");
System.out.println("请输入要修改的管理员编号 ");
String S=scanner.next();
String []Ssplitst=S.split(",");
String c1=Ssplitst[0];
String sql1="SELECT * FROM manager where mID='"+S+"'";
rs= stmt.executeQuery(sql1);
int lll=0;
while(rs.next())
{
String a222 =rs.getString(1);
String b222 =rs.getString(2);
String c222 =rs.getString(3);
String d222 =rs.getString(4);
String e222 =rs.getString(5);
String f222 =rs.getString(6);
System.out.println(a222+","+b222+" ,"+c222+","+d222+","+e222+","+f222);
lll++;
}
if(lll==0)
{
System.out.println( "没有这个管理员请重新输入");
}
else
{
System.out.println( "要修改的信息");
String aa=scanner.next();
System.out.println("要将它改为");
String bb=scanner.next();
String updateSql="UPDATE manager SET mName='"+bb+"' WHERE mID='"+S+"'";
int hh=stmt.executeUpdate(updateSql); //返回记录影响的条数
if(hh!=0)
{
System.out.println("修改成功!");
}
System.out.println("是否继续修改yes/no no返回主菜单");
String o=scanner.next();
if(o.startsWith("yes"))
{
System.out.println();
};
if(o.startsWith("no"))
{
mm=1;
System.out.println();
};
}
}
break;
}
break;
}
String updateSql="UPDATE manager SET mSex='"+c1+"' WHERE mID=1";
int t=stmt.executeUpdate(updateSql); //返回记录影响的条数
if(t!=0){
System.out.println("修改成功!");}
}break;
}
case 4:
System.out.println(" 图书借阅信息: ");
System.out.println(" 1. 查询图书借阅信息信息: ");
System.out.println(" 2. 插入图书借阅信息: ");
System.out.println(" 3. 删除图书借阅信息: ");
System.out.println(" 4. 修改图书借阅信息: ");
System.out.println(" 5. 返回上一级 ");
int d=scanner.nextInt();
switch(d){
case 1:
System.out.println(" 1. 查询图书借阅信息: ");
String Sql4 = "SELECT * FROM borrowbook ";
rs= stmt.executeQuery(Sql4);
while(rs.next()){
String bookID =rs.getString(1);
String reaID =rs.getString(2);
String outDate =rs.getString(3);
String yhDate =rs.getString(4);
System.out.println(bookID+","+reaID+","+outDate+","+yhDate);
}
break;
}
case 2:
int zz=0;
while(zz!=1){
System.out.println(" 2. 插入图书借阅信息: ");
System.out.println("请按顺序插入图书的的编号,读者编号,图书借出日期,图书归还日期");
String str=scanner.next();
String []splitst=str.split(",");
String a11=splitst[0];
String a12=splitst[1];
String a13=splitst[2];
String a14=splitst[3];
//String a15=splitst[4];
//String a16=splitst[5];
String insertSql="INSERT INTO borrowbook(bookID,reaID,outDate,yhDate) VALUES('"+a11+"','"+a12+"','"+a13+"','"+a14+"')";
int ii=stmt.executeUpdate(insertSql); //返回记录影响的条数
if(ii!=0){
System.out.println("插入成功!");
}
System.out.println("是否继续插入yes/no no返回主菜单");
String k=scanner.next();
if(k.startsWith("yes"))
{
System.out.println();
};
if(k.startsWith("no"))
{
zz=1;
System.out.println();
};
}
break;
}
case 3:
int ll=0;
while(ll!=1){
System.out.println(" 3. 删除图书借阅信息: ");
System.out.println("请输入要删除的图书条码号:");
String Str=scanner.next();
String []Splitst=Str.split(",");
String b3=Splitst[0];
String sql1="SELECT * FROM borrowbook where bookID='"+b3+"'";
rs= stmt.executeQuery(sql1);
int kkk=0;
while(rs.next())
{
String a22 =rs.getString(1);
String b22 =rs.getString(2);
String c22 =rs.getString(3);
String d22 =rs.getString(4);
// String e22 =rs.getString(5);
//String f22 =rs.getString(6);
System.out.println(a22+","+b22+" ,"+c22+","+d22);
kkk++;
}
if(kkk==0)
{
System.out.println( "没有这本书请重新输入");
}
else
{
System.out.println( "您是否真的要删除? yes/no");
String k=scanner.next();
if(k.startsWith("y"))
{String deleSql= "DELETE FROM borrowbook WHERE bookID='"+b3+"'";
int p=stmt.executeUpdate(deleSql); //返回记录影响的条数
if(p!=0){
System.out.println("删除成功!");
}
System.out.println("是否继续删除yes/no no返回主菜单");
String l=scanner.next();
if(l.startsWith("yes"))
{
System.out.println();
};
if(l.startsWith("no"))
{
ll=1;
System.out.println();
};
}
}
}
String deleSql= "DELETE bookID FROM borrowbook WHERE
bookID='"+b3+"'";
int k=stmt.executeUpdate(deleSql); //返回记录影响的条数
if(k!=0){
System.out.println("删除成功!");
}
break;
}
case 4:
int mm=0;
while(mm!=1)
System.out.println(" 4. 修改借阅读书信息: ");
System.out.println("请输入要修改的图书的ID ");
String S=scanner.next();
String []Ssplitst=S.split(",");
String c1=Ssplitst[0];
String sql1="SELECT * FROM borrowbook where bookID='"+S+"'";
rs= stmt.executeQuery(sql1);
int lll=0;
while(rs.next())
{
String a222 =rs.getString(1);
String b222 =rs.getString(2);
String c222 =rs.getString(3);
String d222 =rs.getString(4);
String e222 =rs.getString(5);
String f222 =rs.getString(6);
System.out.println(a222+","+b222+" ,"+c222+","+d222);
lll++;
}
if(lll==0)
{
System.out.println( "没有这条记录请重新输入");
}
else
{
System.out.println( "要修改的信息");
String aa=scanner.next();
System.out.println("要将借阅日期改为");
String bb=scanner.next();
String updateSql="UPDATE borrowbook SET outDate='"+bb+"' WHERE bookID='"+S+"'";
int hh=stmt.executeUpdate(updateSql); //返回记录影响的条数
if(hh!=0)
{
System.out.println("修改成功!");
}
System.out.println("是否继续修改yes/no no返回主菜单");
String o=scanner.next();
if(o.startsWith("yes"))
{
System.out.println();
};
if(o.startsWith("no"))
{
mm=1;
System.out.println();
};
}
break;
}
break;
}
String updateSql="UPDATE borrow SET outDate='"+c1+"' WHERE
bookName='数据库'";
int t=stmt.executeUpdate(updateSql); //返回记录影响的条数
if(t!=0){
System.out.println("修改成功!");}
break;
}
break;
}
case 5:
System.out.println(" 还书信息: ");
System.out.println(" 1. 查询还书信息: ");
System.out.println(" 2. 插入还书信息: ");
System.out.println(" 3. 删除还书信息: ");
System.out.println(" 4. 修改还书信息: ");
System.out.println(" 5. 返回上一级 ");
int e=scanner.nextInt();
switch(e){
case 1:
System.out.println(" 1. 查询还书信息: ");
sql = "SELECT * FROM return ";
rs= stmt.executeQuery(sql);
while(rs.next()){
String reaID =rs.getString(1);
String bookID =rs.getString(2);
String bookName =rs.getString(3);
String inDate =rs.getString(4);
System.out.println(reaID+","+bookID+","+bookName+","+ inDate);
}
break;
}
case 2:
System.out.println(" 2. 插入还书信息: ");
System.out.println("请按顺序插入读者卡号,图书编号,图书名称,还书日期");
String str=scanner.next();
String []splitst=str.split(",");
String e1=splitst[0];
String e2=splitst[1];
String e3=splitst[2];
String e4=splitst[3];
String insertSql="INSERT INTO returnbook(reaID,bookID,bookName,inDate) VALUES('"+e1+"','"+e2+"','"+e3+"','"+e4+"')";
int h=stmt.executeUpdate(insertSql); //返回记录影响的条数
if(h!=0){
System.out.println("插入成功!"); }
break;
}
case 3:
System.out.println(" 3. 删除还书书信息: ");
System.out.println("请输入要删除的读者证号:");
String Str=scanner.next();
String []Splitst=Str.split(",");
String f3=Splitst[0];
String deleSql= "DELETE FROM return WHERE reaID='"+f3+"'";
int w=stmt.executeUpdate(deleSql); //返回记录影响的条数
if(w!=0){
System.out.println("删除成功!");}
break;
}break;
}
case 6:
System.out.println(" 罚款信息信息: ");
System.out.println(" 1. 查询罚款信息: ");
System.out.println(" 2. 插入罚款信息: ");
System.out.println(" 3. 删除罚款信息: ");
System.out.println(" 4. 修改罚款信息: ");
int g=scanner.nextInt();
switch(g){
case 1:
System.out.println(" 1. 查询罚款信息: ");
String Sssql = "SELECT * FROM fine ";
rs= stmt.executeQuery(Sssql);
while(rs.next()){
String str =scanner.next();
String reaID =rs.getString(1);
String reaNo =rs.getString(2);
String reaName =rs.getString(3);
String bookID =rs.getString(2);
String outDate =rs.getString(3);
String overDate =rs.getString(4);
String fine =rs.getString(5);
System.out.println(reaID+","+bookID+","+outDate+","+overDate+","+fine);
}
break;
}
case 2:
System.out.println(" 1. 插入罚款信息: ");
System.out.println("请按顺序插入读者卡号,号,借书日期超出日期,应缴罚款");
String str=scanner.next();
String []splitst=str.split(",");
String g1=splitst[0];
String g2=splitst[1];
String g3=splitst[2];
String g4=splitst[3];
String g5=splitst[4];
//String g6=splitst[5];
//String g7=splitst[6];
String insertSql="INSERT INTO return(reaID,bookID,outDate,fine) VALUES('"+g1+"','"+g2+"','"+g3+"','"+g4+"','"+g5+"')";
int h=stmt.executeUpdate(insertSql); //返回记录影响的条数
if(h!=0){
System.out.println("插入成功!"); }
break;
case 3:
System.out.println(" 3. 删除罚款信息: ");
System.out.println("请输入要删除的读者证号:");
String Str=scanner.next();
String []Splitst=Str.split(",");
String r=Splitst[0];
String deleSql= "DELETE FROM fine WHERE reaID='"+r+"'";
int x=stmt.executeUpdate(deleSql); //返回记录影响的条数
if(x!=0){
System.out.println("删除成功!");}
break;
}break;
}
case 7:
System.out.println(" 借阅历史信息: "); System.out.println(" 1. 查询借阅历史信息: ");
System.out.println(" 2. 插入借阅历史信息: ");
System.out.println(" 3. 删除借阅历史信息: ");
System.out.println(" 4. 修改借阅历史信息: ");
System.out.println(" 5. 返回上一级 ");
int h=scanner.nextInt();
switch(h){
case 1:
System.out.println(" 1. 查询历史借阅信息: ");
String Sql7 = "SELECT * FROM borrowhistory ";
rs= stmt.executeQuery(Sql7);
while(rs.next()){
String bookID =rs.getString(1);
String reaID =rs.getString(2);
String bookName=rs.getString(3);
String bookWriter=rs.getString(4);
String outDate =rs.getString(5);
String yhDate =rs.getString(6);
System.out.println(bookID+","+reaID+","+bookName+","+bookWriter+","+outDate+","+yhDate);
}
break;
}
case 2:
System.out.println(" 2. 插入图书历史借阅信息: ");
System.out.println("请按顺序插入图书的的编号,读者编号,,图书借出日期,图书归还日期");
String str=scanner.next();
String []splitst=str.split(",");
String a11=splitst[0];
String a12=splitst[1];
String a13=splitst[2];
String a14=splitst[3];
String a15=splitst[4];
String a16=splitst[5];
String insertSql="INSERT INTO borrowhistory(bookID,realID,outDate,yhDate) VALUES('"+a11+"','"+a12+"','"+a13+"','"+a14+"')";
int i=stmt.executeUpdate(insertSql); //返回记录影响的条数
if(i!=0){
System.out.println("插入成功!"); }
break;
}
case 3:
System.out.println(" 3. 删除图书历史借阅信息: "); System.out.println("请输入要删除的图书条码号:");
String Str=scanner.next();
String []Splitst=Str.split(",");
String d3=Splitst[0];
String deleSql= "DELETE bookID FROM borrowhistory WHERE bookID='"+d3+"'";
int k=stmt.executeUpdate(deleSql); //返回记录影响的条数
if(k!=0){
System.out.println("删除成功!");}
break;
}
case 4:
System.out.println(" 4. 修改图书借阅历史信息: ");
System.out.println("请输入要修改的图书的借出日期 ");
String S=scanner.next();
String []Ssplitst=S.split(",");
String c1=Ssplitst[0];
String updateSql="UPDATE borrow SET outDate='"+c1+"' WHERE bookName='数据库'";
int t=stmt.executeUpdate(updateSql); //返回记录影响的条数
if(t!=0){
System.out.println("修改成功!");}
break;
}
}}
}
}
else{
System.out.println("非法用户");
}
}catch(SQLException e) {
e.printStackTrace();
}
rs.close();
stmt.close();
conn.close();
}
}
}
}