Giriş
Şöyle yaparız
docker run \ --name pg \ -e POSTGRES_USER=myuser \ -e POSTGRES_PASSWORD=root \ -e POSTGRES_DB=db \ --rm \ -p 5432:5432 \ postgres
Örnek - JDBC URL
Şöyle yaparız
HikariConfig configuration = new HikariConfig(); configuration.setJdbcUrl("jdbc:postgresql://localhost:5432/db"); configuration.setUsername("myuser"); configuration.setPassword("root"); HikariDataSource hikariDataSource = new HikariDataSource(configuration); Connection connection = hikariDataSource.getConnection();
Örnek - dataSourceClassName
Şöyle yaparız
Properties props = new Properties(); props.setProperty("dataSourceClassName", "org.postgresql.ds.PGSimpleDataSource"); props.setProperty("dataSource.user", "myuser"); props.setProperty("dataSource.password", "root"); props.setProperty("dataSource.databaseName", "db"); props.put("dataSource.logWriter", new PrintWriter(System.out)); HikariConfig config = new HikariConfig(props); HikariDataSource ds = new HikariDataSource(config);
Properties props = new Properties(); props.setProperty("dataSourceClassName", "org.postgresql.ds.PGSimpleDataSource"); props.setProperty("username", "myuser"); props.setProperty("password", "root"); props.setProperty("dataSource.databaseName", "db"); props.put("dataSource.logWriter", new PrintWriter(System.out)); HikariConfig config = new HikariConfig(props); HikariDataSource ds = new HikariDataSource(config);
Örnek
Properties dosyası şöyledir
dataSourceClassName=org.postgresql.ds.PGSimpleDataSource dataSource.user=test dataSource.password=test dataSource.databaseName=mydb dataSource.portNumber=5432 dataSource.serverName=localhost
Hiç yorum yok:
Yorum Gönder