JAVA:数据库操作封装(2)

相关资料

/**
   * @function executeUpdate
   * @throws SQLException
   */
  public void executeBatch() throws SQLException {
    if (prepstmt != null)
      prepstmt.executeBatch();
  }

  /**
   * @function addBatch
   * @param value String
   * @throws SQLException
   */
  public void addBatch(String value) throws SQLException {
    prepstmt.addBatch(value);
  }

  /**
   * @function setString
   * @param index int
   * @param value String
   * @throws SQLException
   */
  public void setString(int index,String value) throws SQLException {
    prepstmt.setString(index, value);
  }

  /**
   * @function setInt
   * @param index int
   * @param value int
   * @throws SQLException
   */
  public void setInt(int index,int value) throws SQLException {
    prepstmt.setInt(index,value);
  }

  /**
   * @function setBoolean
   * @param index int
   * @param value boolean
   * @throws SQLException
   */
  public void setBoolean(int index,boolean value) throws SQLException {
    prepstmt.setBoolean(index,value);
  }

  /**
   * @function setDate
   * @param index int
   * @param value Date
   * @throws SQLException
   */
  public void setDate(int index,Date value) throws SQLException {
    prepstmt.setDate(index,value);
  }

  /**
   * @function setLong
   * @param index int
   * @param value long
   * @throws SQLException
   */
  public void setLong(int index,long value) throws SQLException {
    prepstmt.setLong(index,value);
  }

  /**
   * @function setFloat
   * @param index int
   * @param value float
   * @throws SQLException
   */
  public void setFloat(int index,float value) throws SQLException {
    prepstmt.setFloat(index,value);
  }

  /**
   * @function setBytes
   * @param index int
   * @param value byte[]
   * @throws SQLException
   */
  public void setBytes(int index,byte[] value) throws SQLException{
    prepstmt.setBytes(index,value);
  }

  /**
   * @function setBinaryStream
   * @param index int
   * @param value InputStream
   * @param len int
   * @throws SQLException
   */
  public void setBinaryStream(int index,InputStream value,int len) throws SQLException{
    prepstmt.setBinaryStream(index,value,len);
  }

  /**
   * @function setTimestamp
   * @param index int
   * @param timestamp Timestamp
   * @throws SQLException
   */
  public void setTimestamp(int index,Timestamp timestamp) throws SQLException {
    prepstmt.setTimestamp(index, timestamp);
  }

  /**
   * @function setAutoCommit
   * @param value boolean
   * @throws SQLException
   */
  public void setAutoCommit(boolean value) throws SQLException{
    if(this.conn != null)
      this.conn.setAutoCommit(value);
  }

  /**
   * @function commit
   * @throws SQLException
   */
  public void commit() throws SQLException{
    this.conn.commit();
  }

  /**
   * @function rollback
   * @throws SQLException
   */
  public void rollback() throws SQLException{
    this.conn.rollback();
  }

  /**
   * @function close
   * @throws Exception
   */
  public void close(){
    try{
      if (rs != null) {
        rs.close();
        rs = null;
      }
    }catch(Exception e){
      System.out.println("dbBean close rs error!");
    }finally{
      try{
        if (stmt != null) {
          stmt.close();
          stmt = null;
        }
      }catch(Exception e){
        System.out.println("dbBean close stmt error!");
      }finally{
        try{
          if (prepstmt != null) {
            prepstmt.close();
            prepstmt = null;
          }
        }catch(Exception e){
          System.out.println("dbBean close prepstmt error!");
        }finally{
          try{
            if (conn != null) {
              conn.close();
              conn = null;
            }
          }catch(Exception e){
            System.out.println("dbBean close conn error!");
          }
        }
      }
    }
  }

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值