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

📄 library.java

📁 图书馆管理系统,图书馆管理系统图书馆管理系统图书馆管理系统图书馆管理系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
  		System.out.println("ForName:"+e.getMessage());}
			

			try    
				{
				 Connection con=DriverManager.getConnection(url);
				 Statement s=con.createStatement();
				 ResultSet rs1=s.executeQuery("select * from user");
				 String k;
				 t1.setEnabled(true);
				 t1.setText("用户名"+"\t"+"密码"+"\n");
				 boolean boo=false;
				 while((boo=rs1.next())==true)
				 {			
							
							t1.append
							(rs1.getString("user_id")+"\t"+rs1.getString("password")+"\n");
							 					
				 }

				 con.close();						
				}
			catch(SQLException ee) 
				{System.out.println("SQLException :" + ee.getMessage( ));}
		}
		public void actionPerformed(ActionEvent ee)
		{
			if(ee.getSource()==flush)
			{
				try    
				{
				 Connection con=DriverManager.getConnection(url);
				 Statement s=con.createStatement();
				 ResultSet rs1=s.executeQuery("select * from user");
				 String k;
				 t1.setEnabled(true);
				 t1.setText("用户名"+"\t"+"密码"+"\n");
				 boolean boo=false;
				 while((boo=rs1.next())==true)
				 {			
							
							t1.append
							(rs1.getString("user_id")+"\t"+rs1.getString("password")+"\n");
							 					
				 }

				 con.close();						
				}
				catch(SQLException ee1) 
				{System.out.println("SQLException :" + ee1.getMessage( ));}
			}
			
			
		}
	}
//显示学生档案
class Studentlist extends JFrame implements ActionListener
	{	
		String url="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};"
	      +"DBQ=library.mdb";
		JTextArea t1;
		JButton flush;
		
		Studentlist()
		{			
		    super("用户列表");
		    flush=new JButton("刷新");		
			t1=new JTextArea(16,50);
			add(t1,BorderLayout.CENTER);
			add(flush,BorderLayout.SOUTH);
			flush.addActionListener(this);
			
			setSize(500,300);
			show();
			
			
			try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
  	catch(ClassNotFoundException e){
  		System.out.println("ForName:"+e.getMessage());}
			

			try    
				{
				 Connection con=DriverManager.getConnection(url);
				 Statement s=con.createStatement();
				 ResultSet rs1=s.executeQuery("select * from student");
				 String k;
				 t1.setEnabled(true);
				 t1.setText("学号"+"\t"+"姓名"+"\t"+"性别"+"\t"+"班级代码"+"\n");
				 boolean boo=false;
				 while((boo=rs1.next())==true)
				 {			
							
			      t1.append
			      (rs1.getString("student_no")+"\t"+rs1.getString("name")+"\t"+rs1.getString("sex")+"\t"+rs1.getString("class_no")+"\n");
							 					
				 }

				 con.close();						
				}
			catch(SQLException ee) 
				{System.out.println("SQLException :" + ee.getMessage( ));}
		}
		public void actionPerformed(ActionEvent ee)
		{
			if(ee.getSource()==flush)
			{
				try    
				{
				 Connection con=DriverManager.getConnection(url);
				 Statement s=con.createStatement();
				 ResultSet rs1=s.executeQuery("select * from student");
				 String k;
				 t1.setEnabled(true);
				 t1.setText("学号"+"\t"+"姓名"+"\t"+"性别"+"\t"+"班级代码"+"\n");
				 boolean boo=false;
				 while((boo=rs1.next())==true)
				 {			
							
					t1.append
						(rs1.getString("student_no")+"\t"+rs1.getString("name")+"\t"+rs1.getString("sex")+"\t"+rs1.getString("class_no")+"\n");
							 					
				 }

				 con.close();						
				}
				catch(SQLException ee1) 
				{System.out.println("SQLException :" + ee1.getMessage( ));}
			}
			
			
		}
		}
  //添加学生档案
  class Studentadd extends JFrame implements ActionListener
{
   	Container c;
	JPanel panel1,panel2;
	JLabel StudentnoLabel,NameLabel,SexLabel,ClassnoLabel;
	JTextField StudentnoField,NameField,SexField,ClassnoField;
	JButton AddBtn,CancelBtn;
	Studentadd()
	{
		super("添加用户");
		c=getContentPane();
		c.setLayout(new BorderLayout());
		StudentnoLabel=new JLabel("学号",JLabel.CENTER);
		NameLabel=new JLabel("姓名",JLabel.CENTER);
		SexLabel=new JLabel("性别",JLabel.CENTER);
		ClassnoLabel=new JLabel("班级代号",JLabel.CENTER);
		StudentnoField=new JTextField(10);
		NameField=new JTextField(10);
		SexField=new JTextField(10);
		ClassnoField=new JTextField(10);
		
	
		AddBtn=new JButton("添加");
		CancelBtn=new JButton("取消");
		AddBtn.addActionListener(this);
		CancelBtn.addActionListener(this);
		
		panel1=new JPanel();
        panel1.setLayout(new GridLayout(4,2));
		panel1.add(StudentnoLabel);
		panel1.add(StudentnoField);
		panel1.add(NameLabel);
		panel1.add(NameField);
		panel1.add(SexLabel);
		panel1.add(SexField);
		panel1.add(ClassnoLabel);
		panel1.add(ClassnoField);
		c.add(panel1,BorderLayout.CENTER);
		panel2=new JPanel();
		panel2.add(AddBtn);
		panel2.add(CancelBtn);
		c.add(panel2,BorderLayout.SOUTH);
		setSize(370,180);
		show();
		
	}
	public void actionPerformed(ActionEvent e)
{
		if(e.getSource() == AddBtn)
		{if(StudentnoField.getText().trim().equals(""))
				{
					JOptionPane.showMessageDialog(null,"学号不能为空!");
				}
				else if(NameField.getText().trim().equals(""))
				{
					JOptionPane.showMessageDialog(null,"姓名不能为空!");
				}
			    else if(SexField.getText().trim().equals(""))
				{
					JOptionPane.showMessageDialog(null,"性别不能为空!");
				}
				else if(ClassnoField.getText().trim().equals(""))
				{
					JOptionPane.showMessageDialog(null,"班级号不能为空!");
				}
			
			
			
			
			
				else
				{
					try{Addstudent();}
  		     catch(SQLException ee){
  			System.out.println("SQLException:"+ee.getMessage());}
				}
				}
				
				
				
				
				
				
  	     	
		if(e.getSource() == CancelBtn)
		{dispose();
			}
		
		
	}
	
	
	public void Addstudent()throws SQLException
  {
  	try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
  	catch(ClassNotFoundException e){
  		System.out.println("ForName:"+e.getMessage());}
  		String conURL="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};"+"DBQ=library.mdb";
  		Connection ExlCon=DriverManager.getConnection(conURL);
  		Statement Exlstmt=ExlCon.createStatement();
  		 
       String a1="'"+StudentnoField.getText().trim()+"'";
  		String a2="'"+NameField.getText().trim()+"'";
  		String a3="'"+SexField.getText().trim()+"'";
  		String a4="'"+ClassnoField.getText().trim()+"'";
  	    String a5="select * from student where student_no='"+
				StudentnoField.getText().trim()+"'";
				
				ResultSet a6=Exlstmt.executeQuery(a5);
				if(a6.next())
         {
         	
         	
         	JOptionPane.showMessageDialog(null,"该学生已存在!");
         	
         	
         	 }
  		
  	     else {
  	     		String temp="INSERT INTO student VALUES ("+a1+","+a2+","+a3+","+a4+")";
  		
  		Exlstmt.executeUpdate(temp);
  		JOptionPane.showMessageDialog(null,"添加成功");
  		
  		
  			ExlCon.close();
  	     	
  	     	
  	     	}
  }
  }
  
  //删除学生档案
  class Delstudent extends JFrame implements ActionListener
{
	JPanel panel1,panel2;
	Container c;
	JLabel NameLabel,StudentnoLabel;
	JTextField StudentnoField,NameField;
	JButton YesBtn,CancelBtn;
	Delstudent()
	{
		super("删除学生档案");
		c=getContentPane();
		c.setLayout(new BorderLayout());
		StudentnoLabel=new JLabel("学号",JLabel.CENTER);
		NameLabel=new JLabel("姓名",JLabel.CENTER);
		StudentnoField=new JTextField(7);
		NameField=new JTextField(6);
		YesBtn=new JButton("确定");
		CancelBtn=new JButton("取消");
		YesBtn.addActionListener(this);
		CancelBtn.addActionListener(this);
		panel1=new JPanel();
		panel1.setLayout(new GridLayout(2,2));
		panel1.add(StudentnoLabel);
		panel1.add(StudentnoField);
		panel1.add(NameLabel);
		panel1.add(NameField);
		panel2=new JPanel();
		panel2.add(YesBtn);
		panel2.add(CancelBtn);
		c.add(panel1,BorderLayout.CENTER);
		c.add(panel2,BorderLayout.SOUTH);
		setSize(250,110);
		show();
		}
		public void actionPerformed(ActionEvent e)
	{
		
		if(e.getSource()==CancelBtn)
		{
			this.dispose();
		}
		else if(e.getSource()==YesBtn)
		{
		
			
				if(StudentnoLabel.getText().trim().equals(""))
				{
					JOptionPane.showMessageDialog(null,"学号不能为空!");
				}
				else if(NameField.getText().trim().equals(""))
				{
					JOptionPane.showMessageDialog(null,"姓名不能为空!");
				}
				else
				{
					try{Delstudent();}
  		     catch(SQLException ee){
  			System.out.println("SQLException:"+ee.getMessage());}
				}
			
			
			
			
			
			
			
		}
	}
	

public void Delstudent()throws SQLException
  {try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
  	catch(ClassNotFoundException e){
  		System.out.println("ForName:"+e.getMessage());}
  		String conURL="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};"+"DBQ=library.mdb";
  		Connection ExlCon=DriverManager.getConnection(conURL);
  		Statement Exlstmt=ExlCon.createStatement();
  		String c1="'"+StudentnoField.getText().trim()+"'",
  		       c2="'"+NameField.getText().trim()+"'";
  		
  		
	 
	 String b5="select * from student where student_no="+c1+"and name="+c2;
				
				
				ResultSet b4=Exlstmt.executeQuery(b5);
         if(b4.next())
         {
         	String a1="'"+StudentnoField.getText().trim()+"'";
  		String temp="DELETE FROM student WHERE student_no="+a1;
  		
  		Exlstmt.executeUpdate(temp);
         	
         	JOptionPane.showMessageDialog(null,"学生档案已删除!");
         	ExlCon.close();
         	
         	}
  		
  	     else {
  	     	
  	     	
  		JOptionPane.showMessageDialog(null,"姓名学号不正确或者不存在该学生!");
  		
  	
   
          }
  	
  	
  	
  	
  	
  	
  	}
  	}
  	
  	
  	//学生档案修改
  	
  	class Studentmodify extends JFrame implements ActionListener
{
	JPanel panel1,panel2;
	Container c;
	JLabel StudentnoLabel,NameLabel,SexLabel,ClassnoLabel,NewStudentnoLabel,NewNameLabel,NewSexLabel,NewClassnoLabel;
	JTextField StudentnoField,NameField,SexField,ClassnoField,NewStudentnoField,NewNameField,NewSexField,NewClassnoField;
	JButton ShowBtn,UpdateBtn,CancelBtn;
    Studentmodify()
	{
		super("更改学生档案");
		c=getContentPane();
		c.setLayout(new BorderLayout());
		StudentnoLabel=new JLabel("原学号",JLabel.CENTER);
		NameLabel=new JLabel("原姓名",JLabel.CENTER);
		SexLabel=new JLabel("原性别",JLabel.CENTER);
		ClassnoLabel=new JLabel("原班级号",JLabel.CENTER);
		StudentnoField=new JTextField(10);
		NameField=new JTextField(10);
		SexField=new JTextField(10);
		ClassnoField=new JTextField(10);
		
		
		
		
		NewStudentnoLabel=new JLabel("新学号",JLabel.CENTER);
		
		
		
		NewNameLabel=new JLabel("新姓名",JLabel.CENTER);
		NewSexLabel=new JLabel("新性别",JLabel.CENTER);
		NewClassnoLabel=new JLabel("新班级号",JLabel.CENTER);
		NewStudentnoField=new JTextField("学号不可更改",10);
		NewStudentnoField.setEditable(false);
		NewNameField=new JTextField(10);
		NewSexField=new JTextField(10);
		NewClassnoField=new JTextField(10);
		
		
		
		
		
		
		
		ShowBtn=new JButton("显示");
		UpdateBtn=new JButton("更新");
		CancelBtn=new JButton("取消");
		ShowBtn.addActionListener(this);
		UpdateBtn.addActionListener(this);
		CancelBtn.addActionListener(this);
		panel1=new JPanel();
		panel1.setLayout(new GridLayout(4,4));
		panel1.add(StudentnoLabel);
		panel1.add(StudentnoField);
		panel1.add(NewStudentnoLabel);
		panel1.add(NewStudentnoField);
		
		
		
		panel1.add(NameLabel);
		panel1.add(NameField);
		panel1.add(NewNameLabel);
		panel1.add(NewNameField);
		
		panel1.add(SexLabel);
		panel1.add(SexField);
		panel1.add(NewSexLabel);
		panel1.add(NewSexField);
		
		panel1.add(ClassnoLabel);
		panel1.add(ClassnoField);
		panel1.add(NewClassnoLabel);
		panel1.add(NewClassnoField);
		
		
		
		
		
		
		
		panel2=new JPanel();
		panel2.add(ShowBtn);
		panel2.add(UpdateBtn);
		panel2.add(CancelBtn);
		
		c.add(panel1,BorderLayout.CENTER);
		c.add(panel2,BorderLayout.SOUTH);
		setSize(400,180);
		show();
		
	}
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==ShowBtn)
		{try{Showall();}

⌨️ 快捷键说明

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