美文网首页alreadyHiKariCP
Mariadb java操作(四) 四种方式初始化Hikaric

Mariadb java操作(四) 四种方式初始化Hikaric

作者: ShootHzj | 来源:发表于2020-08-19 10:01 被阅读0次
    package com.github.shoothzj.demo.hikaricp;
    
    import com.zaxxer.hikari.HikariConfig;
    import com.zaxxer.hikari.HikariDataSource;
    import lombok.extern.slf4j.Slf4j;
    import org.junit.Test;
    
    import java.io.PrintWriter;
    import java.util.Properties;
    
    /**
     * Four ways to Init Hikari Config.
     * @author hezhangjian
     */
    @Slf4j
    public class HikariConfigInitTest {
    
        @Test
        public void way1() {
            HikariConfig config = new HikariConfig();
            config.setMaximumPoolSize(8);
            config.setPoolName("Pool1");
            HikariDataSource ds1 = new HikariDataSource(config);
        }
    
        @Test
        public void way2() {
            HikariDataSource ds = new HikariDataSource();
            ds.setJdbcUrl("jdbc:mysql://localhost:3306/simpsons");
            ds.setUsername("bart");
            ds.setPassword("51mp50n");
        }
    
        @Test
        public void way3() {
            HikariConfig config = new HikariConfig("/some/path/hikari.properties");
            HikariDataSource hikariDataSource = new HikariDataSource(config);
        }
    
        @Test
        public void way4() {
            Properties props = new Properties();
            props.setProperty("dataSourceClassName", "org.postgresql.ds.PGSimpleDataSource");
            props.setProperty("dataSource.user", "test");
            props.setProperty("dataSource.password", "test");
            props.setProperty("dataSource.databaseName", "mydb");
            props.put("dataSource.logWriter", new PrintWriter(System.out));
    
            HikariConfig config = new HikariConfig(props);
            HikariDataSource ds = new HikariDataSource(config);
        }
    
    }
    
    

    相关文章

      网友评论

        本文标题:Mariadb java操作(四) 四种方式初始化Hikaric

        本文链接:https://www.haomeiwen.com/subject/rohljktx.html