mybaits 学习3-多个数据源

数据源添加mysql和oracle
代码见具体github:https://github.com/JNUpython/springboot2/tree/develop

ojdbc依赖无法下载

github上面下载该jar 并通过maven命令本地安装

mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0.2 -Dpackaging=jar -Dfile=./libs/ojdbc7-12.1.0.2.jar 

mybatis 全局配置xml文件,以及数据库配置文件

mybaits 学习3-多个数据源_第1张图片
image.png

mybatis-mysql.xml




    
    
    
    
    
    
    
    
    

    
        
        
        
    

    
    

        
            
            
                
                
                
                
            
        

        
            
            
                
                
                
                
            
        
    
    
        
        
    

application-dev.properties

# 开发环境配置文件

# 程序中会用到的一些自定义变量
com.didispace.blog.name=学习spring
com.didispace.blog.title=进阶
com.dispspace.blog.randomString=${random.value}
com.dispspace.blog.root=${com.didispace.blog.title}-${com.didispace.blog.title}


# mysql test 数据库
database.url1=jdbc:mysql://127.0.0.1:3306/test?serverTimezone=CTT&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true
database.username1=root
database.password1=123456
database.driverName1=com.mysql.cj.jdbc.Driver

# oracle 数据库
database.url2=jdbc:oracle:thin:@127.0.0.1:1521:orcl
database.username2=c##kean
database.password2=123456
database.driverName2=oracle.jdbc.driver.OracleDriver

执行结果

22:11:16.601 [main] DEBUG org.apache.ibatis.logging.LogFactory - Logging initialized using 'class org.apache.ibatis.logging.slf4j.Slf4jImpl' adapter.
22:11:16.811 [main] DEBUG org.apache.ibatis.datasource.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections.
22:11:16.812 [main] DEBUG org.apache.ibatis.datasource.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections.
22:11:16.812 [main] DEBUG org.apache.ibatis.datasource.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections.
22:11:16.812 [main] DEBUG org.apache.ibatis.datasource.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections.
22:11:16.916 [main] INFO com.mybatis.MybatisTest - Mapper class: class com.sun.proxy.$Proxy6
22:11:16.928 [main] DEBUG org.apache.ibatis.transaction.jdbc.JdbcTransaction - Opening JDBC Connection
22:11:19.052 [main] DEBUG org.apache.ibatis.datasource.pooled.PooledDataSource - Created connection 927327686.
22:11:19.052 [main] DEBUG org.apache.ibatis.transaction.jdbc.JdbcTransaction - Setting autocommit to false on JDBC Connection [oracle.jdbc.driver.T4CConnection@3745e5c6]
22:11:19.054 [main] DEBUG com.mybatis.dao.EmployeeMapper.getEmpById - ==>  Preparing: select * from tbl_employee where id = ? 
22:11:19.184 [main] DEBUG com.mybatis.dao.EmployeeMapper.getEmpById - ==> Parameters: 101(Integer)
22:11:19.277 [main] DEBUG com.mybatis.dao.EmployeeMapper.getEmpById - <==      Total: 1
22:11:19.278 [main] INFO com.mybatis.MybatisTest - 101 jack man
22:11:19.278 [main] DEBUG org.apache.ibatis.transaction.jdbc.JdbcTransaction - Resetting autocommit to true on JDBC Connection [oracle.jdbc.driver.T4CConnection@3745e5c6]
22:11:19.279 [main] DEBUG org.apache.ibatis.transaction.jdbc.JdbcTransaction - Closing JDBC Connection [oracle.jdbc.driver.T4CConnection@3745e5c6]
22:11:19.279 [main] DEBUG org.apache.ibatis.datasource.pooled.PooledDataSource - Returned connection 927327686 to pool.
22:11:19.279 [main] INFO com.mybatis.MybatisTest - 查询完成!

你可能感兴趣的:(mybaits 学习3-多个数据源)