๐Ÿ‘จ‍๐Ÿ’ป Back End/JDBC

1) ๋น„๊ด€์  ๋ฝ (Pessimistic Lock)์„ ์ด์šฉํ•œ ๋™์‹œ์„ฑ ์ด์Šˆ ํ•ด๊ฒฐ (1) ๊ฐœ์š” ์ด์ „ ๊ฒŒ์‹œ๊ธ€์—์„œ Synchronized ํ‚ค์›Œ๋“œ๋ฅผ ์ด์šฉํ•˜์—ฌ ๋™์‹œ์„ฑ ์ด์Šˆ๋ฅผ ํ•ด๊ฒฐํ•˜์˜€์œผ๋‚˜ ์‹ค๋ฌด ํ™˜๊ฒฝ์—์„œ๋Š” 1๋Œ€์˜ WAS๋งŒ์„ ์ด์šฉํ•˜์ง€ ์•Š๊ณ  ์—ฌ๋Ÿฌ ๋Œ€์˜ WAS ์„œ๋ฒ„๋ฅผ ์šด์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— Synchronized๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค. ์™œ๋ƒํ•˜๋ฉด Synchronized ํ‚ค์›Œ๋“œ๋Š” ํ•œ ๋Œ€์˜ WAS ์„œ๋ฒ„์—์„œ๋งŒ ๋™๊ธฐํ™” ํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ๋”ฐ๋ผ์„œ, ์—ฌ๋Ÿฌ ๋Œ€์˜ WAS ์„œ๋ฒ„์—์„œ DB์˜ ํŠน์ • ๋ฐ์ดํ„ฐ๋ฅผ ๋ณ€๊ฒฝํ•˜๋Š” ๊ฒฝ์šฐ, Race Condition ์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด์ฒ˜๋Ÿผ Race Condition์„ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ์ด๋ฒˆ์—๋Š” MySQL์—์„œ ์ œ๊ณตํ•˜๋Š” Lock์„ ์ด์šฉํ•ด ๋น„๊ด€์  ๋ฝ์œผ๋กœ ํ•ด๊ฒฐํ•ด๋ณด๊ณ ์ž ํ•œ๋‹ค. ์ด์ „ ๊ฒŒ์‹œ๊ธ€์˜ "(2) ์ดˆ๊ธฐ ์„ค์ •" ๋ถ€๋ถ„๋ถ€ํ„ฐ "(4)..
1) Synchrozied ํ‚ค์›Œ๋“œ๋ฅผ ์ด์šฉํ•œ ๋™์‹œ์„ฑ ์ด์Šˆ ํ•ด๊ฒฐ (1) ๊ฐœ์š” ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„œ๋ฒ„ (WAS) ์—์„œ๋Š” HTTP ์š”์ฒญ ๋‹น User Thread๋ฅผ ๋งŒ๋“ค๊ธฐ ๋•Œ๋ฌธ์— 1๋Œ€์˜ WAS์—์„œ ๋‹จ์ผ DB ๋กœ์˜ ์„ธ์…˜์€ ์š”์ฒญ ๊ฐœ์ˆ˜๋งŒํผ ์‚ฌ์šฉํ•œ๋‹ค. ๋”ฐ๋ผ์„œ, ์—ฌ๋Ÿฌ DB ์„ธ์…˜์—์„œ ํŠน์ • ๋ฐ์ดํ„ฐ๋ฅผ ๋ณ€๊ฒฝํ•˜๋Š” Race Condition ์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด์ฒ˜๋Ÿผ Race Condition ์„ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด Java์—์„œ ์ œ๊ณตํ•˜๋Š” Synchronized ํ‚ค์›Œ๋“œ๋ฅผ ์ด์šฉํ•ด ํ•ด๊ฒฐํ•ด๋ณด๊ณ ์ž ํ•œ๋‹ค. (2) ์ดˆ๊ธฐ ์„ค์ • ์‹ค์Šต ํ™˜๊ฒฝ MySQL 8.0 JDK 11 (IntelliJ) Spring boot 2.7 Spring JDBC 5.3.29 application.properties ์„ค์ • spring.datasource.driver-class-n..
1) ์ปค๋„ฅ์…˜ ํ’€ (Connection Pool) (1) ์ปค๋„ฅ์…˜ ํ’€์ด๋ž€ JDBC API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€ ์—ฐ๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด Connection ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๋Š” ์ž‘์—…์€ ๋น„์šฉ์ด ๊ต‰์žฅํžˆ ๋งŽ์ด ๋“œ๋Š” ์ž‘์—… ์ค‘ ํ•˜๋‚˜์ด๋‹ค. Connection ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ณผ์ •์„ ํ•œ ๋ฒˆ ์‚ดํŽด๋ณด์ž! โ‘  ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ DB ๋“œ๋ผ์ด๋ฒ„๋ฅผ ํ†ตํ•ด ์ปค๋„ฅ์…˜์„ ์กฐํšŒํ•œ๋‹ค. โ‘ก DB ๋“œ๋ผ์ด๋ฒ„๋Š” DB์™€ TCP/IP ์ปค๋„ฅ์…˜์„ ์—ฐ๊ฒฐํ•œ๋‹ค. (3 way handshake์™€ ๊ฐ™์€ ๋„คํŠธ์›Œํฌ ์—ฐ๊ฒฐ ๋™์ž‘ ๋ฐœ์ƒ) โ‘ข DB ๋“œ๋ผ์ด๋ฒ„๋Š” TCP/IP ์ปค๋„ฅ์…˜์ด ์—ฐ๊ฒฐ๋˜๋ฉด ์•„์ด๋””์™€ ํŒจ์Šค์›Œ๋“œ, ๊ธฐํƒ€ ๋ถ€๊ฐ€ ์ •๋ณด๋ฅผ DB์— ์ „๋‹ฌํ•œ๋‹ค. โ‘ฃ DB๋Š” ์•„์ด๋””, ํŒจ์Šค์›Œ๋“œ๋ฅผ ํ†ตํ•ด ๋‚ด๋ถ€ ์ธ์ฆ์„ ๊ฑฐ์นœ ํ›„ ๋‚ด๋ถ€์— DB๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. โ‘ค DB๋Š” ์ปค๋„ฅ์…˜ ์ƒ์„ฑ์ด ์™„๋ฃŒ๋˜์—ˆ๋‹ค๋Š” ์‘๋‹ต์„ ๋ณด๋‚ธ๋‹ค. โ‘ฅ DB ๋“œ๋ผ..
1) PreparedStatment ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ (1) ๊ฐœ์š” Statment ์ข…๋ฅ˜์—๋Š” Statement, PreparedStatement, CallableStatement 3๊ฐ€์ง€๊ฐ€ ์กด์žฌํ•œ๋‹ค. CallableStatement๋Š” PL/SQL๋ฌธ์„ ํ˜ธ์ถœํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค๊ณ  ํ–ˆ์ง€๋งŒ ์„ฑ๋Šฅ์ƒ ์ด์Šˆ๋กœ ์ธํ•ด ๊ฑฐ์˜ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ธฐ์— Statement๋‚˜ PreparedStatement๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ์‹ค๋ฌด ํ™˜๊ฒฝ์—์„œ๋Š” Statement๋Š” ์“ฐ์ง€ ์•Š๊ณ  PreparedStatement๋งŒ ์‚ฌ์šฉํ•˜๋Š”๋ฐ ๊ทธ ์ด์œ ๋ฅผ ์•Œ์•„ ๋ณด์ž! (2) Statement, PreparedStatement ๋™์ž‘ ๋ฐฉ์‹ Statement ๋ฐ PreparedStatement ๋ฐฉ์‹์€ ์•„๋ž˜์™€ ๊ฐ™์€ ๊ณตํ†ต์ ์ธ ์‹คํ–‰ ๊ณผ์ •์„ ๊ฑฐ์น˜๊ฒŒ ๋œ๋‹ค. โ‘  ๊ตฌ๋ฌธ ๋ถ„์„ (Parsin..
1) ์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” ๋ฉ”์†Œ๋“œ ์ •๋ฆฌ in JDBC (1) Connection ๊ฐ์ฒด setAutoCommit( boolean bool) ํ˜„์žฌ ์„ธ์…˜์˜ AutoCommit ์„ค์ • getAutoCommit() ํ˜„์žฌ ์„ธ์…˜์˜ AutoCommit ์„ค์ • ๊ฐ’ ๋ฆฌํ„ด commit() ํŠธ๋žœ์žญ์…˜ commit ์‹คํ–‰ rollback() ํŠธ๋žœ์žญ์…˜ rollback ์‹คํ–‰ createStatement() Statement ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ๋ฆฌํ„ด preparedStatement(String sql) PreparedStatement ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ๋ฆฌํ„ด ํ˜„์žฌ์—๋Š” Statement ๊ฐ์ฒด๋ณด๋‹ค๋Š” PreparedStatement ๊ฐ์ฒด๋ฅผ ์ž์ฃผ ์‚ฌ์šฉํ•œ๋‹ค. setSavepoint(String name) Savepoint ์ง€์ • getTransactionIsola..
1) JDBC๋ฅผ ์ด์šฉํ•œ CRUD ์‹ค์Šต (1) ์ดˆ๊ธฐ ์„ค์ • โ‘  ์‹ค์Šต ํ™˜๊ฒฝ MySQL 8.0 JDK 11 (IDE : IntelliJ) Spring boot 2.7 โ‘ก ์‹ค์Šต ํ…Œ์ด๋ธ” ์ƒ์„ฑ // ํ…Œ์ด๋ธ” ์ƒ์„ฑ CREATE TABLE MEMBER ( ID INT not null auto_increment, NAME VARCHAR(100) not null, JOB VARCHAR(30) not null, primary key (ID)); // ์ดˆ๊ธฐ ๋ฐ์ดํ„ฐ ์ƒ์„ฑ INSERT INTO MEMBER VALUES (1, "userA", 'Student'); INSERT INTO MEMBER VALUES (2, "userB", 'Student'); INSERT INTO MEMBER VALUES (3, "userC", 'Stude..
1) JDBC (Java Database Connectivity) (1) JDBC๋ž€ Java ๊ธฐ๋ฐ˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ €์žฅ ๋ฐ ์—…๋ฐ์ดํŠธํ•˜๊ฑฐ๋‚˜, ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ๋ฅผ Java์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” ์ž๋ฐ” API์ด๋‹ค. JDBC๋Š” Java ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•ด JDBC API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์—ฐ๋™ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ์ž๋ฃŒ๋ฅผ ์ฟผ๋ฆฌ(Query)ํ•˜๊ฑฐ๋‚˜ ์—…๋ฐ์ดํŠธํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ œ๊ณตํ•œ๋‹ค. ๋˜ํ•œ, DBMS์˜ ์ข…๋ฅ˜์— ์ƒ๊ด€์—†์ด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์—ฐ๊ฒฐํ•˜๊ณ  ์ž‘์—…์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค. (2) JDBC Architecture Java Application์—์„œ JDBC API๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด JDBC Driver Manager๊ฐ€ DB ์ œํ’ˆ์— ๋”ฐ๋ฅธ ๋“œ๋ผ์ด๋ฒ„๋ฅผ ์ƒ์„ฑํ•˜์—ฌ JDBC..
Dev_sHu
'๐Ÿ‘จ‍๐Ÿ’ป Back End/JDBC' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก