⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 processthread.java

📁 JAVA图书馆管理系统 sqlserver2000 + SWING + look and feel
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            }
            
            int i = 0;
            
            ResultSet rs1 = stmt.executeQuery(sql1);
            
           while(rs1.next()) {

                borrowBooks[i] = new BorrowBook();
               
                borrowBooks[i].borrowDate = rs1.getDate("borrowDate");
                
                borrowBooks[i].returnDate = rs1.getDate("returnDate");
                
                System.out.println("\n"+ borrowBooks[i].borrowDate.toString() + "\n" + borrowBooks[i].returnDate.toString());
                
                i++;
                
            }
            
            ResultSet rs2 = stmt.executeQuery(sql2);
            
            i = 0;
            
            while(rs2.next()) {
                
            	borrowBooks[i].name = rs2.getString("name");
            	
            	borrowBooks[i].ISBN = rs2.getString("ISBN");
                
            	System.out.println("\n"+ borrowBooks[i].name);
                
                i++;
            } 
              
            for(int j = 0;j<i;j++){
            	
            	ps.println("start");
            
            	ps.println(borrowBooks[j].name);
             	
             	ps.println(borrowBooks[j].ISBN);
             	
             	ps.println(borrowBooks[j].borrowDate);
                  
                ps.println(borrowBooks[j].returnDate);
            	
            }
            
            ps.println("end");
            
            rs.close();
            
            rs1.close();
            
            rs2.close();
            
            conn.close();
            
            stmt.close();

		} catch (Exception e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
	
	}
	
	
	public void search(){
		
		try {
			
			PrintStream ps = new PrintStream(cs.getOutputStream());
			
			String ID = bfc.readLine();
	        
	        String readerID = null;
	        
	        String readerName = null;
	        
	        String readerDep = null;
	        
	        String readerPhone = null;
	        
	        String readeraddress = null;
	        
	        String readerother = null;  
	        
	        BorrowBook[] borrowBooks = new BorrowBook[10];
			
	        //连接数据库(不用类方法是为了避免代码重复)
	        String userName = "sa"; // Your Database user id

			String userPassword = "sa"; // Your Database password
			
			String JDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
			
			String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=library";
			
			Connection conn;
			
			Statement stmt;
			
			Class.forName(JDriver);
			
			conn = DriverManager.getConnection(url,userName,userPassword);
		
			stmt = conn.createStatement();
			
			//搜索信息
			
			String sql = "select * from reader where ID = '" + ID + "'"; //查询读者名
            
			String sql1 = "select * from borrow where readerID = " + "'" + ID + "'"; //查询借阅日期和还书日期
			
            String sql2 = "select * from book where ISBN in(select bookISBN from borrow where readerID =" + "'" + ID + "'" + ")"; //查询书名
            
            ResultSet rs = stmt.executeQuery(sql);
            
            while(rs.next()){
                
            	readerID = rs.getString("ID");
            	
            	readerName = rs.getString("name");
                
                readerDep = rs.getString("department");               
                
                readerPhone = rs.getString("mobilephone");     
                
                readeraddress = rs.getString("address");
                
                readerother = rs.getString("other");
                
                System.out.println("\n"+ readerID + " " + readerName + " " + readerDep + " " + readerPhone + " " + readeraddress + " " + readerother);
                
                ps.println("K");
                
                ps.println(readerID);
                
                ps.println(readerName);
                
                ps.println(readerDep);
                
                ps.println(readerPhone);
                
                ps.println(readeraddress);
                
                ps.println(readerother);

            }
            
            int i = 0;
            
            ResultSet rs1 = stmt.executeQuery(sql1);
            
            while(rs1.next()) {

                borrowBooks[i] = new BorrowBook();
               
                borrowBooks[i].borrowDate = rs1.getDate("borrowDate");
                
                borrowBooks[i].returnDate = rs1.getDate("returnDate");
                
                System.out.println("\n"+ borrowBooks[i].borrowDate.toString() + "\n" + borrowBooks[i].returnDate.toString());
                
                i++;
                
            }
            
            ResultSet rs2 = stmt.executeQuery(sql2);
            
            i = 0;
            
            while(rs2.next()) {
                
            	borrowBooks[i].name = rs2.getString("name");
            	
            	borrowBooks[i].ISBN = rs2.getString("ISBN");
                
            	System.out.println("\n"+ borrowBooks[i].name);
                
                i++;
            } 
              
            for(int j = 0;j<i;j++){
            	
            	ps.println("start");
            
            	ps.println(borrowBooks[j].name);
             	
             	ps.println(borrowBooks[j].ISBN);
             	
             	ps.println(borrowBooks[j].borrowDate);
                  
                ps.println(borrowBooks[j].returnDate);
            	
            }
            
            ps.println("end");
            
            rs.close();
            
            rs1.close();
            
            rs2.close();
            
            conn.close();
            
            stmt.close();
			
		} catch (Exception e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		
	}

	public void remove(){
		
		try {
			
			PrintStream ps = new PrintStream(cs.getOutputStream());
			
			String ID = bfc.readLine();
			
			String userName = "sa"; // Your Database user id

			String userPassword = "sa"; // Your Database password
			
			String JDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
			
			String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=library";
			
			Connection conn;
			
			Statement stmt;
			
			Class.forName(JDriver);
			
			conn = DriverManager.getConnection(url,userName,userPassword);
		
			stmt = conn.createStatement();
			
			String sql= "select * from borrow where readerID='" + ID + "'";

			ResultSet rs = stmt.executeQuery(sql);
			
			if(rs.next()){
				
				ps.println("removefaild");
				
			}else{
				
				String sql1 = "delete from reader where ID='" + ID + "'"; //编辑SQL语句
				
				int iRet = stmt.executeUpdate(sql1);
				
				if(iRet != 0 ){
					
					ps.println("removeOK");
					
				}
				
			}
			
			

		} catch (Exception e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		
		
		
	}
	
	public void login(){
		
		try {
			
			//连接数据库
			String userName = "sa"; // Your Database user id

			String userPassword = "sa"; // Your Database password
			
			String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=library";
			
			Connection conn;
			
			Statement stmt;
			
			Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
			
			conn = DriverManager.getConnection(url,userName,userPassword);
		
			stmt = conn.createStatement();
			
			System.out.println("成功连接到数据库...");
			
			System.out.println("监听客户端验证请求...");
			
			//监听客户端请求			
			
			PrintStream ps = new PrintStream(cs.getOutputStream());
			
			String inputuser = bfc.readLine();
			
			String inputpassword = bfc.readLine();
			
			String sql= "select * from reader where ID = '" + inputuser + "'";

			ResultSet rs = stmt.executeQuery(sql);
			
			//验证客户端请求		
			if(rs.next()){
				
				if(rs.getString("ID").equals(inputuser)){
					
					System.out.println("用户名验证成功...");
					
					System.out.println("密码验证中...");
					
					if(rs.getString("password").equals(inputpassword)){
							
						System.out.println("密码验证成功...");
						
						System.out.println();
						
						if(rs.getString("role").equals("0")){
							
							System.out.println("管理员用户登陆");
							
							ps.println("Welcome1");
							
						}
						if(rs.getString("role").equals("1")){
							
							System.out.println("普通用户登陆");
							
							ps.println("Welcome");
						}		
						
					}
					else{
						
						System.out.println("密码验证失败...");

						ps.println("Sorry");
						
					}
					
				}else{
					
					System.out.println("用户名验证失败...");
					
					System.out.println(inputuser);
					
					ps.println("Sorryuser");
					
				}
	
			}
			
			conn.close();
			
			stmt.close();
			
			
		    			
		} catch (Exception e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		
	}
	
	public void run(){
		
		
		
		try {
			
			bfc = new BufferedReader(new InputStreamReader(cs.getInputStream()));
			
			sn = bfc.readLine();
			
			if(sn.equals("login")){
				
				System.out.println("登陆");
				
				login();
				
			}
			
			if(sn.equals("search")){
				
				System.out.println("搜索读者");
				
				search();		
				
			}
			
			if(sn.equals("add")){
				
				System.out.println("插入读者");
				
				add();
				
			}
			
			if(sn.equals("remove")){
				
				System.out.println("删除读者");
				
				remove();
				
			}
			if(sn.equals("addbook")){
				
				System.out.println("增加书籍");
				
				addbook();
			}
			if(sn.equals("searchbook")){
				
				System.out.println("搜索书籍");
				
				searchbook();
			}
			if(sn.equals("searchm")){
				
				System.out.println("模糊搜索读者");
				
				searchm();
			}
			if(sn.equals("editreader")){
				
				System.out.println("编辑读者");
				
				editreader();
				
			}
			if(sn.equals("borrowbook")){
				
				System.out.println("借阅书籍");
				
				borrowbook();
			}
			if(sn.equals("Nsearch")){
				
				System.out.println("普通读者查询");
				
				Nsearch();
				
			}
			if(sn.equals("makedefault")){
				
				System.out.println("初始化数据");
				
				makedefault();	
				
			}
			if(sn.equals("returnbook")){
				
				System.out.println("归还书籍");
				
				returnbook();
				
			}
			
		} catch (Exception e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}	
		
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -