[Spring] JdbcTemplate์ด๋?
๐ก JdbcTemplate์ด๋?
All SQL operations performed by this class are logged at debug level, using "org.springframework.jdbc.core.JdbcTemplate" as log category.
์ spring ์ฌ์ ์ ๋์จ ์ค๋ช ์ ๋ณด๋ฉด ์ ์ ์๋ฏ์ด,
์คํ๋ง์์ ์ ๊ณตํ๋ SQL ์ฐ์ฐ๋ค์ ์ํ ํ ์ ์๋๋ก ํด์ฃผ๋ JDBC ์ฝ๋์ฉ ๊ธฐ๋ณธ ํ ํ๋ฆฟ์ ๋งํ๋ค.
์ฆ, ์คํ๋ง์ JDBC๋ฅผ ์ด์ฉํ๋ DAO์์ ์ฌ์ฉํ ์ ์๋๋ก ๋ค์ํ ํ ํ๋ฆฟ๊ณผ ์ฝ๋ฐฑ์ ์ ๊ณตํ๋๋ฐ
JdbcTemplate์ ๊ทธ ์ค ํ๋์ด๋ค.
์ฐธ๊ณ :
JdbcTemplate (Spring Framework 5.2.8.RELEASE API)
Execute a query for a result object, given static SQL. Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded JdbcOperations.queryForObject(String, Class, Object...) method with nu
docs.spring.io
์์ ๋ค๋ค๋ JdbcContext์ ์ ์ฌํ์ง๋ง ํจ์ฌ ๊ฐ๋ ฅํ๊ณ ํธ๋ฆฌํ ๊ธฐ๋ฅ์ ์ ๊ณตํด์ค๋ค.
โ๏ธ JdbcTemplate ์ด๊ธฐํ ๋ฐฉ๋ฒ
public class UserDao {
private JdbcTemplate jdbcTemplate;
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
this.dataSource = dataSource;
}
}
JdbcTemplate์ ์ ์ธํด์ค ํ ์์ฑ์์ ํ๋ผ๋ฏธํฐ๋ก DataSource๋ฅผ ์ฃผ์ ํด์ฃผ์
๐ ์ ๋ฆฌ
์ฐธ๊ณ ๋ฌธ์ :
ํ ๋น์ ์คํ๋ง3 (์ด์ผ๋ฏผ)