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

📄 updatereader.java

📁 基于目前许多中小型公司, 机关,中小学校,大学院系等都有自己的图书库, 供内部人员借阅。传统的手工登记办法
💻 JAVA
字号:
/**
 * @(#)UpdateReader.java
 *
 *
 * @author 
 * @version 1.00 2009/5/15
 */


import javax.swing.*;
import java.awt.*;
import java.sql.*;
import java.awt.event.*;

public class UpdateReader extends JFrame implements ActionListener {
	JLabel Jl1,Jl2,Jl3,Jl4,Jl5,Jl6,Jl7;
	JTextField Jt1,Jt2,Jt3,Jt4,Jt5,Jt6,Jt7;
	JButton Jb1,Jb2;
    public UpdateReader() {
    	Container c=this.getContentPane();
    	c.setLayout(null);
    	//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	Jl1=new JLabel("读者编号:");
    	Jl2=new JLabel("读者姓名:");
    	Jl3=new JLabel("读者类型:");
    	Jl4=new JLabel("可借图书:");
    	Jl5=new JLabel("已借图书:");
    	Jt1=new JTextField(10);
    	Jt2=new JTextField(20);
    	Jt3=new JTextField(20);
    	Jt4=new JTextField(20);
    	Jt5=new JTextField(20);
    	Jb1=new JButton("确定");
    	Jb2=new JButton("修改");
    	Jb1.addActionListener(this);
    	Jb2.addActionListener(this);
    	JPanel p4,p1, p2,p3,p23;
    	p4=new JPanel();
    	p4.add(Jl1);
    	p4.add(Jt1);
    	p4.add(Jb1);
    	p1=new JPanel();
    	p1.setLayout(new BoxLayout(p1,BoxLayout.X_AXIS));
    	p1.add(Box.createHorizontalStrut(150));
    	p1.add(Jb2);
    	p1.add(Box.createHorizontalStrut(100));
    	p2=new JPanel(new GridLayout(4,1,10,10));
    	p3=new JPanel(new GridLayout(4,1,10,10));
    	p23=new JPanel();
    	p23.setLayout(new BoxLayout(p23,BoxLayout.X_AXIS));
    	p23.add(Box.createHorizontalStrut(20));
    	p23.add(p2);
    	p23.add(p3);
    	p23.add(Box.createHorizontalStrut(15));
    	p2.add(Jl2);
    	p2.add(Jl3);
    	p2.add(Jl4);
    	p2.add(Jl5);
    	p3.add(Jt2);
    	p3.add(Jt3);
    	p3.add(Jt4);
    	p3.add(Jt5);
    	p4.setBounds(0,0,400,50);
    	p23.setBounds(0,50,400,180);
    	p1.setBounds(0,250,400,50);
    	c.add(p4);
    	c.add(p23);
    	c.add(p1);
    	this.setBounds(320,200,400,340);
    	this.setVisible(true);
    	this.setTitle("修改读者"); 		
    }
    public void actionPerformed(ActionEvent e){
    	Connection con;
        PreparedStatement sql;
        ResultSet rs;
        boolean boo=false;
      try {  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
          }
     catch(ClassNotFoundException f){}
      try {  
             String bianhao,name,type;
             String max,now;
             if(e.getSource().equals(Jb1)){
             bianhao=Jt1.getText();
             con=DriverManager.getConnection("jdbc:odbc:tushuguan");
             	sql=con.prepareStatement("SELECT * FROM reader where rid=?");
             	sql.setString(1,bianhao);
             	rs=sql.executeQuery();
             if(bianhao.equals("")){
             JOptionPane.showMessageDialog(this,"读者编号不能为空!","提示对话框",JOptionPane.WARNING_MESSAGE);
             }
             else if(!rs.next()){
             		JOptionPane.showMessageDialog(this,"所要修改的读者不存在!","提示对话框",JOptionPane.WARNING_MESSAGE);
             	    }	
             else{boo=true;
             	Jt2.setText(rs.getString(2));
             	Jt3.setText(rs.getString(3));
             	Jt4.setText(rs.getString(4));
             	Jt5.setText(rs.getString(5));
             	con.close();
             	
             }
        }
         if(e.getSource().equals(Jb2)){
             con=DriverManager.getConnection("jdbc:odbc:tushuguan");
             sql=con.prepareStatement("update reader set rname=?,type=?,num=?,yijie=? where rid=?");
             bianhao=Jt1.getText();
             name=Jt2.getText();
             type=Jt3.getText();
             max=Jt4.getText();
             now=Jt5.getText();	
             sql.setString(5,bianhao);
             sql.setString(1,name);
             sql.setString(2,type);
             sql.setString(3,max);
             sql.setString(4,now);
             sql.executeUpdate();  
             JOptionPane.showMessageDialog(this,"修改读者成功!","提示对话框",JOptionPane.WARNING_MESSAGE);
    	con.close();
         } 
      }   

      catch(SQLException e2) 
           {  System.out.println(e2);
          }
   } 
    
    	public static void main(String args[])
    	{
    		new UpdateReader();
    		}
    
}

⌨️ 快捷键说明

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