This is the 11th day of my participation in the August More text Challenge. For details, see: August More Text Challenge

Following the previous configuration:

(2) The configuration in application.properties is as follows:

# database
mybatis.type-aliases-package=com.tjm.pojo
mybatis.mapper-locations=classpath:mapper/*.xml
Copy the code

(3) Add Datebase

In the General interface, the User selects the name of the role created by himself, and the password is the password of the corresponding role. After filling in the password, click Test Connection in the lower left corner. After the Test is successful, click Apply, and then click Schemas.

(4) The configuration in application.yml is as follows:

spring:
  datasource:
    username: 'tjm'
    password: '123'
    If the time zone error is reported, add a time zone serverTimezone
    url: jdbc:oracle:thin:@localhost:1521:XE
    driver-class-name: oracle.jdbc.driver.OracleDriver
    type: com.alibaba.druid.pool.DruidDataSource

    Connection pool property
    By default, Spring Boot does not inject these values
    # Druid Data source proprietary configuration
    initialSize: 5
    minIdle: 5
    maxActive: 20
    maxWait: 60000
    timeBetweenEvictionRunsMillis: 60000
    minEvictableIdleTimeMillis: 300000
    validationQuery: SELECT 1 FROM DUAL
    testWhileIdle: true
    testOnBorrow: false
    testOnReturn: false
    Mysql > cache psCache; oracle > cache psCache
    poolPreparedStatements: true

    # Configure stat: monitor statistics, log4j: log records, and WALL: defend against SQL injection
    # if allowed times wrong Java. Lang. ClassNotFoundException: org.. Apache log4j. Priority
    # import log4j dependence can, Maven address: https://mvnrepository.com/artifact/log4j/log4j
    filters: stat,wall,log4j
    maxPoolPreparedStatementPerConnectionSize: 20
    useGlobalDataSourceStat: true
    connectionProperties: druid.stat.mergeSql=true; druid.stat.slowSqlMillis=500
Copy the code

Among the above parameters:

Usrname corresponds to the User we connect to in the Database,password corresponds to the password, and URL corresponds to the URL in the Database.

Test whether the connection is connected

Write to test:

 @Autowired
    DataSource dataSource;

    @Test
    void contextLoads(a) throws SQLException {
        System.out.println("Data source >>>>>>" + dataSource.getClass());
        Connection connection = dataSource.getConnection();
        System.out.println("Connection > > > > > > > > >" + connection);
        System.out.println("Contact address >>>>>" + connection.getMetaData().getURL());
        connection.close();
    }

Copy the code

The output is:

You can see that we are connected to the data source and address, the test is successful!