图书管理系统

  • v0_290147
    了解作者
  • 4.1MB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-14 05:39
    上传日期
简单的JAVA管理系统,连接上数据库,java简单搭建。
library.rar
内容介绍
import java.awt.*; import javax.swing.*; import java.awt.Dimension; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.ResultSet; import java.sql.*; /** * <p>Title: </p> * * <p>Description: </p> * * <p>Copyright: Copyright (c) 2008</p> * * <p>Company: </p> * * @author not attributable * @version 1.0 */ //该类用于管理读者信息 public class Readermanage extends JFrame { public Readermanage() { try { jbInit(); } catch (Exception exception) { exception.printStackTrace(); } Dimension size = getToolkit().getScreenSize(); setLocation((size.width - 600) / 2, (size.height - 400) / 2); } private void jbInit() throws Exception { getContentPane().setLayout(null); setSize(new Dimension(651, 588)); this.setTitle("读者信息"); lblFind.setText("按"); lblFind.setBounds(new Rectangle(16, 15, 17, 15)); cbWay.setBounds(new Rectangle(40, 10, 95, 23)); lblFindit.setText("查找"); lblFindit.setBounds(new Rectangle(141, 14, 29, 15)); txtWhat.setBounds(new Rectangle(40, 45, 94, 21)); btnFind.setBounds(new Rectangle(183, 12, 66, 53)); btnFind.setText("查找"); btnFind.addActionListener(new FrReadermanage_btnFind_actionAdapter(this)); btnEdit.setBounds(new Rectangle(258, 12, 66, 53)); btnEdit.setText("修改"); btnEdit.addActionListener(new FrReadermanage_btnEdit_actionAdapter(this)); btnDelete.setBounds(new Rectangle(333, 12, 66, 53)); btnDelete.setToolTipText(""); btnDelete.setText("删除"); btnDelete.addActionListener(new FrReadermanage_btnDelete_actionAdapter(this)); btnExit.setBounds(new Rectangle(482, 12, 66, 53)); btnExit.setText("关闭"); btnExit.addActionListener(new FrReadermanage_btnExit_actionAdapter(this)); jScrollPane1.setBounds(new Rectangle(13, 83, 615, 464)); btnFlush.setBounds(new Rectangle(407, 12, 66, 53)); btnFlush.setText("刷新"); btnFlush.addActionListener(new FrReadermanage_btnFlush_actionAdapter(this)); btnKey.setBounds(new Rectangle(557, 12, 66, 53)); btnKey.setText("解锁"); btnKey.addActionListener(new FrReadermanage_btnKey_actionAdapter(this)); this.getContentPane().add(lblFind); this.getContentPane().add(cbWay); this.getContentPane().add(lblFindit); this.getContentPane().add(txtWhat); this.getContentPane().add(btnFind); this.getContentPane().add(jScrollPane1); this.getContentPane().add(btnEdit); this.getContentPane().add(btnDelete); this.getContentPane().add(btnFlush); this.getContentPane().add(btnExit); this.getContentPane().add(btnKey); jScrollPane1.getViewport().add(jTable1); cbWay.addItem("编号"); cbWay.addItem("姓名"); cbWay.addItem("电话"); this.Show(); } JLabel lblFind = new JLabel(); JComboBox cbWay = new JComboBox(); JLabel lblFindit = new JLabel(); JTextField txtWhat = new JTextField(); JButton btnFind = new JButton(); JButton btnEdit = new JButton(); JButton btnDelete = new JButton(); JButton btnExit = new JButton(); JScrollPane jScrollPane1 = new JScrollPane(); JTable jTable1 = new JTable(); JButton btnFlush = new JButton(); JButton btnKey = new JButton(); //该方法用于退出当前Frame public void btnExit_actionPerformed(ActionEvent e) { this.setVisible(false); } //该方法用于显示数据库中所有读者信息 public void Show() { DBC dbc = new DBC(); dbc.getConnection(); ResultSet rs1 = dbc.executeQuery("SELECT 总数=COUNT(*) FROM yonghu"); ResultSet rs2 = dbc.executeQuery("SELECT * FROM yonghu"); try { rs1.next(); int count = rs1.getInt("总数"); rs1.close(); Object[][] cells = new Object[count][8]; int i = 0; while (rs2.next()) { cells[i] = new Object[] {rs2.getInt("Uid"), rs2.getString("Uname"), rs2.getString("Usex"), rs2.getString("Uphone"), rs2.getString("Uaddress"), rs2.getString("Uyue"), rs2.getString("Uregtime"), rs2.getString("Ustate")}; i++; } String[] colnames = {"编号", "姓名", "性别", "电话号码", "住址", "余额", "注册时间", "是否锁定"}; jTable1 = new JTable(cells, colnames); jScrollPane1.getViewport().add(jTable1); } catch (SQLException ex) { } } //该方法用于查找指定读者 public void btnFind_actionPerformed(ActionEvent e) { //栏位判断是否有查询条件 if (txtWhat.getText().equals("")) { javax.swing.JOptionPane.showMessageDialog(this, "请输入查询信息!"); return; } DBC dbc = new DBC(); dbc.getConnection(); String sql = ""; if (((String) cbWay.getSelectedItem()).equals("编号")) { try { //若条件为编号,判断是否为数字 Integer.parseInt(txtWhat.getText()); } catch (NumberFormatException ex2) { javax.swing.JOptionPane.showMessageDialog(this, "编号只能为数字!"); return; } sql = "SELECT * FROM Users WHERE Uid = " + Integer.parseInt(txtWhat.getText()); } else if (((String) cbWay.getSelectedItem()).equals("姓名")) { sql = "SELECT * FROM Users WHERE Uname = '" + txtWhat.getText() + "'"; } else { sql = "SELECT * FROM Users WHERE Uphone = '" + txtWhat.getText() + "'"; } //开始查询 ResultSet rs = dbc.executeQuery(sql); int count = 0; try { //count用于查询共有多少条包含指定条件的信息 while (rs.next()) { count++; } rs.close(); } catch (SQLException ex1) { javax.swing.JOptionPane.showMessageDialog(this, ex1.getMessage().toString()); } Object[][] cells = new Object[count][8]; rs = dbc.executeQuery(sql); try { int i = 0; while (rs.next()) { cells[i] = new Object[] {rs.getInt("Uid"), rs.getString("Uname"), rs.getString("Usex"), rs.getString("Uphone"), rs.getString("Uaddress"), rs.getString("Uyue"), rs.getString("Uregtime"), rs.getString("Ustate")}; i++; } String[] colnames = {"编号", "姓名", "性别", "电话号码", "住址", "余额", "注册时间", "是否锁定"}; jTable1 = new JTable(cells, colnames); jScrollPane1.getViewport().add(jTable1); rs.close(); } catch (SQLException ex) { javax.swing.JOptionPane.showMessageDialog(this, ex.getMessage().toString()); } } //该方法用于调用Show()方法刷新记录 public void btnFlush_actionPerformed(ActionEvent e) { this.Show(); } //该方法用于删除操作 public void btnDelete_actionPerformed(ActionEvent e) { DBC dbc = new DBC(); dbc.getConnection(); int row = jTable1.getSelectedRow(); if (row < 0) { javax.swing.JOptionPane.showMessageDialog(this, "您还未选中任何信息!"); return; } Object value = jTable1.getValueAt(row, 0); int id = Integer.parseInt(value.toStrin
评论
    相关推荐