dbdao2

 /**
  * 設置SQL語句中?為任意對象的對應值 <br>
  *
  * @param index
  *            int 預製值所在位置
  * @param value
  *            Object 預製值
  * @throws SQLException
  *             SQL異常
  */
 public void setObject(int index, Object value) throws SQLException {
  preparedStatement.setObject(index, value);
 }

 /**
  * 設置SQL語句中?為Timestamp的變數的對應值 <br>
  *
  * @param index
  *            int 預製值所在位置
  * @param value
  *            Timestamp 預製值
  * @throws SQLException
  *             SQL異常
  */
 public void setTimestamp(int index, java.sql.Timestamp value) throws SQLException {
  preparedStatement.setTimestamp(index, value);
 }

 /**
  * 創建Statement對象
  */
 public Statement createStatement() throws SQLException {
  statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
  return statement;
 }

 /**
  * 得到Statement物件
  *
  * @return Statement對象
  */
 public Statement getStatement() {
  return statement;
 }

 /**
  * 創建prepareStatement對象
  *
  * @param sql
  *            預設SQL語句
  */
 public void prepareStatement(String sql) throws SQLException {
  preparedStatement = connection.prepareStatement(sql);
 }

 /**
  * 返回PreparedStatement對象
  *
  * @return PreparedStatement對象
  */
 public PreparedStatement getPreparedStatement() {
  return preparedStatement;
 }

 /**
  * 去掉PREPAREDSTATEMENT中的所有已經綁定的參數 <br>
  *
  * @throws SQLException
  *             SQL異常
  */
 public void clearParameters() throws SQLException {
  preparedStatement.clearParameters();
 }

 /**
  * 資料事務提交 要先將自動提交設置狀態設置為不自動﹐然后才commit
  */
 public void commit() throws SQLException {
  try {
   connection.commit();
  } catch (SQLException e) {
   LOG.error(e.toString(), e);
   throw e;
  }finally{
   close();
  }
 }

 /**
  * 資料事務回滾,在執行SQL的過程中出現異常時執行 要先將自動提交設置狀態設置為不自動
  */
 public void rollback() throws SQLException {
  try {
   connection.rollback();
  } catch (SQLException e) {
   LOG.error(e.toString(), e);
   throw e;
  }finally{
   close();
  }
 }

 /**
  * 將查詢的結果放在一個ResultSet中 使用方法:<br>
  * DBDAO dao = new DBDAO(); Result rs = dao.doSQLQueryRS(sql); 解析rs后要顯示關閉
  * rs.close(); dao.close();
  *
  * @param sql
  *            String 任何一條SQL查詢語句形如:select * from tlb_doc where id=?
  * @return ResultSet 查詢結果返回對象集
  * @throws SQLException
  */
 public ResultSet executeQuery(String sql) throws SQLException {
  resultset = null;
  try {
   statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
     ResultSet.CONCUR_READ_ONLY);
   resultset = statement.executeQuery(sql);
   connection.commit();//for DBLink與seq
  } catch (SQLException e) {
   LOG.error(e.toString(), e);
   LOG.error("SQL:" + sql);
   throw e;
  }
  return resultset;
 }

 /**
  * 將查詢的結果放在一個ResultSet中 使用方法:<br>
  * DBDAO dao = new DBDAO(); rs = dao.executeQuery(sql,obj); 解析rs后要顯示關閉
  * rs.close(); dao.close();
  *
  * @param sql
  *            String 任何一條SQL查詢語句形如:select * from tlb_doc where id=?
  * @param args
  *            Object[] 參數對象, 形如︰<p/> Object obj []= new Object[1]; </br>
  *            obj[0] = new String("2"); </br>
  * @return ResultSet 查詢結果返回對象集
  * @throws SQLException
  */
 public ResultSet executeQuery(String sql, Object[] args) throws SQLException {
  resultset = null;
  try {
   preparedStatement = connection.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE,
     ResultSet.CONCUR_READ_ONLY);
   if (args != null) {
    for (int k = 0; k < args.length; k++) {
     preparedStatement.setObject(k + 1, args[k]);
    }
   }
   resultset = preparedStatement.executeQuery();
   connection.commit();//for DBLink與seq
  } catch (SQLException e) {
   LOG.error(e.toString(), e);
   LOG.error("SQL:" + sql);
   for (int i = 0; i < args.length; i++) {
    LOG.error("args[" + i + "]" + args[i]);
   }
   throw e;
  }
  return resultset;
 }

 /**
  * 執行SQL更新語句,針對PreparedStatement﹐可以用于事物處理
  *
  * @return int 執行成功的SQL條數
  * @throws SQLException
  *             SQL異常
  */
 public int executeUpdate() throws SQLException {
  int num = 0;
  System.out.println("aaaaaaa");
  
  try {
   if (preparedStatement != null) {
    System.out.println("ccccccccc");
    num = preparedStatement.executeUpdate();
    System.out.println("bbb="+preparedStatement.getFetchSize()+",num="+num);
    if (isAutoCommit) {
     connection.commit();
    }
   }
  } catch (SQLException e) {
   if (isAutoCommit) {
    connection.rollback();
   }
   LOG.error(e.toString(), e);
   throw e;
  } finally {
   if (preparedStatement != null) {
    preparedStatement.close();
    preparedStatement = null;
   }
  }
  return num;
 }

  /**

dbdao3.txt

*/ }
 

JFrame jf = new JFrame("功能界面"); jf.setBounds(0, 0, 700, 600); jf.setVisible(true); jf.setLayout(null); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton b1 = new JButton("图书入库"); b1.setBounds(20, 90, 150, 80); JButton b2 = new JButton("图书查询"); b2.setBounds(20, 210, 150, 80); JButton b3 = new JButton("图书修改"); b3.setBounds(500, 90, 150, 80); JButton b5 = new JButton("办理借阅证登记"); b5.setBounds(20, 330, 150, 80); JButton b6 = new JButton("图书借阅管理"); b6.setBounds(500, 210, 150, 80); JButton b4 = new JButton("图书删除"); b4.setBounds(500, 330, 150, 80); JButton b7 = new JButton("退出系统"); b7.setBounds(560, 20, 90, 30); ta.setBounds(190, 90, 290, 320); txt.setBounds(120,450,300,30); JButton b8 = new JButton("确定"); b8.setBounds(440,450,70,30); JMenuBar menuBar = new JMenuBar(); JMenu menuManage = new JMenu("图书管理"); JMenu menuAbout = new JMenu("关于系统"); JMenuItem item1 = new JMenuItem("图书列表"); menuManage.add(item1); item1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFrame frame = new JFrame("图书列表"); frame.setSize(600, 400); frame.setLocationRelativeTo(null); ListPanel listPanel = new ListPanel(); frame.add(listPanel); frame.setVisible(true); } }); ActionListener act = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if(e.getSource().equals(b1)) { insertNewbook(); }else if(e.getSource().equals(b3)) { updatebook(); }else if(e.getSource().equals(b4)) { String bid = txt.getText(); if(bid!=null) { if(dbDao.delelteBook(bid)){ int user = JOptionPane.showConfirmDialog(null, "图书删除成功","提示",JOptionPane.YES_NO_OPTION); }else{ int user = JOptionPane.showConfirmDialog(null, "图书删除失败","提示",JOptionPane.YES_NO_OPTION); } }else { return; }部分代码,点击图书删除按钮会直接弹窗提示删除失败并且bid是空值,该怎么获取输入的值并将它传入删除图书方法
05-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值