zoukankan      html  css  js  c++  java
  • lis分析之一一批处理(任务)如何连接数据库的

    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的属性

    一文理解class.getClassLoader().getResourceAsStream(file)和ass.getResourceAsStream(file)区别

  • 相关阅读:
    RN-Android构建失败:Caused by: org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'AwesomeProject'.
    Android更新包下载成功后不出现安装界面
    真机调试: The application could not be installed: INSTALL_FAILED_TEST_ONLY
    react native 屏幕尺寸转换
    Android Studio生成签名文件,自动签名,以及获取SHA1和MD5值
    React Native安卓真机调试
    git提交代码报错Permission denied, please try again
    The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.
    命令行设置快捷命令
    Linux 常用指令
  • 原文地址:https://www.cnblogs.com/zytcomeon/p/14035278.html
Copyright © 2011-2022 走看看