lis分析之一一批處理(任務)如何連線資料庫的
阿新 • • 發佈:2020-11-25
public class ZFBCheckAccountTask extends TaskThread { }
這個類執行時候自動載入了資料庫連線,不明白是如何提前載入的,開始用static { } 去全域性搜尋,未果(現在覺得思路就不對,因為只加載了自己的類,所以只可能載入自己這個類的static{}方法;用提示語全域性搜尋未果,因為連線方法在依賴的jar包中;接著想到了他的父類TaskThread ,對父類進行斷點跟蹤, 在構造方法中
public TaskThread() { LDTaskParamDB tLDTaskParamDB = new LDTaskParamDB(); tLDTaskParamDB.setTaskCode("000000"); tLDTaskParamDB.setTaskPlanCode("000000"); tLDTaskParamDB.setParamName("ServerType"); if (tLDTaskParamDB.getInfo()) {
接著進入
tLDTaskParamDB.getInfo()
public boolean getInfo() { PreparedStatement pstmt = null; ResultSet rs = null; if (!this.mflag) {this.con = DBConnPool.getConnection(); }
在DBConnPool類中有靜態方法
static { for(int nIndex = 0; nIndex < 63; ++nIndex) { dbConns[nIndex] = new DBConn(); } }
接著進入DBConn類中,構造方法
protected DBConn() { this.m_pw = new PrintWriter(this.m_buf, true);this.mGlobalPools = GlobalPools.getInstance(); this.JUrl = new JdbcUrl(); this.bNotInUse = true; }
在進入jdbcURl類中
static { InputStream stream = JdbcUrl.class.getClassLoader().getResourceAsStream("jdbc.properties"); Properties properties = new Properties(); try { logger.info("【資料連線】開始載入資料庫連線配置"); properties.load(stream); JDBC_DB_TYPE = (String)properties.get("jdbc.DBType"); JDBC_DB_NAME = (String)properties.get("jdbc.DBName"); logger.info("【資料連線】對轉碼的資料庫資訊進行進行解碼"); JDBC_IP = ConfigSecret.decode((String)properties.get("jdbc.IP")); JDBC_PORT = ConfigSecret.decode((String)properties.get("jdbc.Port")); JDBC_USERNAME = ConfigSecret.decode((String)properties.get("jdbc.UserName")); JDBC_PASSWORD = ConfigSecret.decode((String)properties.get("jdbc.PassWord")); JDBC_DEFAULT_CONN = (String)properties.get("jdbc.DefaultConn"); String fileConfigFlagStr = (String)properties.get("jdbc.fileConfigFlag"); fileConfigFlag = Boolean.getBoolean(fileConfigFlagStr); logger.info("【資料連線】讀取資料庫連線完成,資料庫連線地址" + JDBC_IP + ",資料庫使用者名稱:" + JDBC_USERNAME); logger.info("【資料連線】開始初始化資料庫連線"); initMultPool(); logger.info("【資料連線】初始化資料庫連線完成"); } catch (Exception var11) {
這裡就是的static 程式碼塊讀取了jdbc.prperties的屬性