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

📄 db.java

📁 完整的合同管理信息系统
💻 JAVA
字号:
package com.ICT.AFC.DB;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Date;
import java.lang.*;
import java.sql.PreparedStatement;


public class DB {

  Connection connect = null;
  ResultSet rs = null;
  PreparedStatement prepstmt = null;

  public DB(DataSource dataSource) {

    try {

      connect = dataSource.getConnection();

    }
    catch (SQLException e) {
      e.printStackTrace();
    }
  }

  public void setAutoCommit(boolean isAutoCommit) throws SQLException {
    try {
      connect.setAutoCommit(isAutoCommit);
    }
    catch (SQLException ex) {
      throw ex;
    }
  }

  public void commit() throws SQLException {
    try {
      connect.commit();
    }
    catch (SQLException ex) {
      connect.rollback();
      throw ex;
    }
  }

  public void rollback() throws SQLException {
    try {
      connect.rollback();
    }
    catch (SQLException ex) {
      throw ex;
    }
  }

  public ResultSet OpenSql(String sql) {
    try {
      Statement stmt = connect.createStatement(ResultSet.
                                               TYPE_SCROLL_INSENSITIVE,
                                               ResultSet.CONCUR_READ_ONLY);
      rs = stmt.executeQuery(sql);
    }
    catch (SQLException ex) {
      ex.printStackTrace();
    }
    return rs;
  }

  public int ExecSql(String sql) {
    int result = 0;
    try {
      Statement stmt = connect.createStatement();
      result = stmt.executeUpdate(sql);
    }
    catch (SQLException ex) {
      System.err.println(ex.getMessage());

    }
    return result;
  }
  public void prepareStatement(String sql) throws SQLException
    {
                 prepstmt = connect.prepareStatement(sql);

    }
    public void setString(int i, String s) throws SQLException {
                  prepstmt.setString(i, s);
          }

          public void setInt(int i, int j) throws SQLException {
                  prepstmt.setInt(i, j);
          }

          public void setBoolean(int i, boolean flag) throws SQLException {
                  prepstmt.setBoolean(i, flag);
          }

          public void setDate(int i, Date date) throws SQLException {
                  prepstmt.setDate(i, date);
          }

          public void setLong(int i, long l) throws SQLException {
                  prepstmt.setLong(i, l);
          }

          public void setFloat(int i, float f) throws SQLException {
                  prepstmt.setFloat(i, f);
          }

          public void setDouble(int i, double f) throws SQLException {
                  prepstmt.setDouble(i, f);
          }

          public void setBytes(int i, byte abyte0[]) throws SQLException {
                  prepstmt.setBytes(i, abyte0);
          }
          public int executeUpdate() throws SQLException {
                if (prepstmt != null)
                        return prepstmt.executeUpdate();
                else
                        return 0;
        }


  public void close() {
    if (connect != null) {
      try {
        connect.close();
        connect = null;
      }
      catch (SQLException ex) {
        System.err.println(ex.getMessage());
      }
    }
  }
}

⌨️ 快捷键说明

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