package com.example.demo.Component;
import java.sql.Connection;
import java.sql.Statement;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
@Component
public class PgSQLRunner implements ApplicationRunner {
@Autowired
DataSource dataSource;
@Autowired
JdbcTemplate jdbcTemplate;
@Override
public void run(ApplicationArguments args) throws Exception {
// TODO Auto-generated method stub
System.out.println("PgSQLRunner ===> START ");
try(Connection connection = dataSource.getConnection()) {
System.out.println("PgSQLRunner ===>" + dataSource.getClass());
System.out.println("PgSQLRunner ===>" + connection.getMetaData());
System.out.println("PgSQLRunner ===>" + connection.getMetaData().getUserName());
Statement statement = connection.createStatement();
String sql = "CREATE TABLE TEST_USER2 (ID INTEGER NOT NULL, name VARCHAR(255), PRIMARY KEY (id))";
statement.executeUpdate(sql);
}
jdbcTemplate.execute("INSERT INTO TEST_USER2 values (5, 'fffff')");
}
}
PgSQLRunner ===>class com.zaxxer.hikari.HikariDataSource
PgSQLRunner ===>HikariProxyDatabaseMetaData@425033914 wrapping org.postgresql.jdbc.PgDatabaseMetaData@11d4d979
PgSQLRunner ===>postgres
잘됨 pgAdmin 초강력 툴이네.
'Python' 카테고리의 다른 글
Uncaught SyntaxError: Cannot use import statement outside a module (0) | 2022.03.31 |
---|---|
순수 Eclipse를 이용한 Spring 개발 (0) | 2022.03.31 |
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. (0) | 2022.03.30 |
/Library/PostgreSQL/14 (0) | 2022.03.30 |
See the log file/Users/junhoha/Documents/workspace-spring414/.metadata/.log. (0) | 2022.03.30 |
최근댓글