WEB开发网
开发学院WEB开发Jsp java数据库的实现 阅读

java数据库的实现

 2008-01-05 10:43:32 来源:WEB开发网   
核心提示:此程序是用java 通过JDBC—DOBC桥利用access作后台制作的一个图书馆治理系统表格:BookInfo(书籍信息)ISBN VARCHAR 20 NOT NULL PKTitle: VARCHAR 30Publisher VARCHAR 30Author VARCHAR 20IsLend VARCHAR 4R

  此程序是用java 通过JDBC—DOBC桥利用access作后台制作的一个图书馆治理系统
  
  表格:
  BookInfo(书籍信息)
  ISBN VARCHAR 20 NOT NULL PK
  Title: VARCHAR 30
  Publisher VARCHAR 30
  Author VARCHAR 20
  IsLend VARCHAR 4
  
  Reader(读者信息)
  ReadID VARCHAR 15 NOT NULL PK
  Name VARCHAR 20
  Class VARCHAR 40
  
  BorrowInfo(借阅信息)
  BorrowID VARCHAR 20 NOT NULL PK
  ReadID VARCHAR 20 NOT NULL
  ISBN VARCHAR 20 NOT NULL
  BorrowDate VARCHAR 20 NOT NULL
  ReturnDate VARCHAR 20 NOT NULL
  源代码如下:
  *****************表格类********************
  //表格的布局
  package Table;
  import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  
  public class Table extends JPanel
  {
  PRivate JPanel labelPanel, fieldsPanel;//定义两块面板对象
  //labelPanel用来放标签,fieldsPanel用来放文本区
  private String labels[] = //标签名
  { "* ISBN:", "名称:", "作者:", "出版社:", /*"借出情况:",*/ //access table1
  "读者编号:", "姓名:", "单位","借出日期","还书日期"};
  
  JTextField ISBN, title, author, publisher,/*isLend,*/readerID,name,workPlace,
  borrowDate, returnDate;
  
  public Table()
  {
  labelPanel = new JPanel();
  labelPanel.setLayout( //指定布局治理器
  new GridLayout( labels.length, 1 ) );
  
  ImageIcon ii = new ImageIcon( "images/icon.jpg" );
  
  for ( int i = 0; i < labels.length; i++ )//加载
  labelPanel.add( new JLabel( labels[ i ], ii, 0) );
  
  // TextField panel
  fieldsPanel = new JPanel();
  fieldsPanel.setLayout( new GridLayout( labels.length, 1 ) );
  
  ISBN = new JTextField( 20 );
  fieldsPanel.add( ISBN );
  
  title = new JTextField( 20 );
  fieldsPanel.add( title );
  
  author = new JTextField( 20 );
  fieldsPanel.add( author );
  
  publisher = new JTextField( 20 );
  fieldsPanel.add( publisher );
  
  readerID = new JTextField( 20 );
  fieldsPanel.add( readerID );
  
  name = new JTextField( 20 );
  fieldsPanel.add( name );
  
  workPlace = new JTextField( 20 );
  fieldsPanel.add( workPlace );
  
  borrowDate = new JTextField( 20 );
  fieldsPanel.add( borrowDate );
  
  returnDate = new JTextField( 20 );
  fieldsPanel.add( returnDate );
  
  setLayout( new GridLayout( 1, 2 ) );//两块面板在GridLayout中呈一行两列
  add( labelPanel );
  add( fieldsPanel );
  }
  }
  ****************操作*********
  
  import Table;
  import java.sql.*;
  import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  import java.util.*;
  import sun.audio.*;
  import java.io.*;
  
  public class LibManager extends JFrame implements ActionListener
  {
  private Table tableArea;//调用Table类
  private JTable output; //显示表的内容
  
  private String url; //指定了帮助程序(在本地文件系统或网络上)定位数据库的数据库URL
  private Connection connect;//Connection对象治理java程序和数据库的连接
  private JScrollPane textpane;//滚动区域对象
  private ResultSet resultSet;//保存结果
  private String passWord;//用户登录权限密码
  private String comp = "manager";//制定密码
  Statement statement ;//将向数据库递交查询
  
  /*--------------------------Menu Component----------------------*/
  private JMenuBar bar;//菜单栏对象
  private JMenu fileMenu,controlMenu,optionMenu,helpMenu;//菜单对象
  private JMenuItem exitItem, grantItem; //菜单项对象
  private JMenuItem findItem1,findItem2,updateItem,insertItem,deleteItem;
  private JMenuItem borrowItem,returnItem,resetItem,refreshItem,advancedItem;
  
  private JMenuItem backgroundColorItem,fontColorItem,musicItem,stopItem;
  private JMenuItem useDisItem, aboutItem;
  
  private Container c = getContentPane();
  private Color color = Color.lightGray;
  private AudioStream asWin, asDouble;
  
  public LibManager()
  {
  super( "LibraryManager 2.0" );
  try
  {
  InputStream inDouble = new FileInputStream ( "绝代双骄.wav" );
  asDouble = new AudioStream ( inDouble );
  InputStream inWin = new FileInputStream ( "Windows 登录音.wav" );
  asWin = new AudioStream ( inWin );
  }
  catch (Exception e )
  {
  e.printStackTrace ( );
  }
  tableArea = new Table( );
  output = new JTable (0, 0);
  
  c.setLayout( new BorderLayout() );//布局治理器
  c.add( new JScrollPane( tableArea ),BorderLayout.NORTH );
  
  textpane = new JScrollPane( output );
  c.add( new JScrollPane( output ),
  BorderLayout.CENTER );
  
  
  /*---------------------------------------------------*/
  //加载菜单对象并注册监听
  /*--------------------------Menu-----------------------*/
  bar = new JMenuBar ( );
  setJMenuBar ( bar );
  /*----------------------File----------------------------*/
  fileMenu = new JMenu ( "系统设置" );
  
  grantItem = new JMenuItem ( "权限密码" );
  grantItem.addActionListener ( this );
  
  exitItem = new JMenuItem ( "退出" );
  exitItem.addActionListener ( this );
  
  fileMenu.add ( grantItem );
  fileMenu.addSeparator ( );
  fileMenu.add ( exitItem );
  
  bar.add ( fileMenu );
  
  /*------------------------------------Control------------------------------*/
  controlMenu = new JMenu ( "功能" );
  
  findItem1 = new JMenuItem ( "借阅查询" );
  findItem1.addActionListener ( this );
  
  findItem2 = new JMenuItem ( "读者查询" );
  findItem2.addActionListener ( this );
  
  updateItem = new JMenuItem ( "更新" );
  updateItem.addActionListener ( this );
  
  insertItem = new JMenuItem ( "插入书籍" );
  insertItem.addActionListener ( this );
  
  deleteItem = new JMenuItem ( "删除书籍" );
  deleteItem.addActionListener ( this );
  
  borrowItem = new JMenuItem ( "借阅" );
  borrowItem.addActionListener ( this );
  
  returnItem = new JMenuItem ( "归还" );
  returnItem.addActionListener ( this );
  
  resetItem = new JMenuItem ( "复位" );
  resetItem.addActionListener ( this );
  
  refreshItem = new JMenuItem ( "刷新" );
  refreshItem.addActionListener ( this );
  
  advancedItem = new JMenuItem ( "高级" );
  advancedItem.addActionListener ( this );
  /////////////////////////////////////////
  password = JOptionPane.showInputDialog ( "治理员权限密码" );
  
  controlMenu.add ( findItem1 );
  controlMenu.add ( findItem2 );
  controlMenu.add ( updateItem );
  controlMenu.add ( insertItem );
  controlMenu.add ( deleteItem );
  controlMenu.add ( borrowItem );
  controlMenu.add ( returnItem );
  controlMenu.add ( resetItem );
  controlMenu.add ( refreshItem );
  controlMenu.addSeparator ( );
  controlMenu.add ( advancedItem );
  if ( password.compareToIgnoreCase ( comp ) != 0 )//判定两个字符串是否相等
  {
  updateItem.setEnabled ( false );
  insertItem.setEnabled ( false );
  deleteItem.setEnabled ( false );
  borrowItem.setEnabled ( false );
  returnItem.setEnabled ( false );
  advancedItem.setEnabled ( false );
  }//end_if
  bar.add ( controlMenu );
  
  /*------------------------------Option-------------------------------*/
  optionMenu = new JMenu ( "选项" );
  
  backgroundColorItem = new JMenuItem ( "Background Color" );
  backgroundColorItem.addActionListener ( this );<

Tags:java 数据库 实现

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接