Back-end/Spring

[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์€ ๊ทธ ์ค‘ ํ•˜๋‚˜์ด๋‹ค.

 

์ฐธ๊ณ :

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/core/JdbcTemplate.html

 

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 (์ด์ผ๋ฏผ)

๋ฐ˜์‘ํ˜•