DB λ°μ΄ν° λΆλ¬μ¬ λ [try catch finally λ°©μκ³Ό try resources μ μ°¨μ΄]
μΌλ°μ μΌλ‘ DB λ°μ΄ν°λ₯Ό λΆλ¬ μ¬ λ try catch finally λ°©μμ μ΄μ©νλ€.
νμ§λ§, java 7 μ΄νλ‘ try resources λ κ°λ₯νκ² λλλ°
μ΄λ tryμμ λ€μ΄κ°λ λ°μ΄ν°μ μμκ° μ€μνλ©°, AutoCloseable μΈν°νμ΄μ€λ₯Ό μμνκ³ μλ ν΄λμ€λ§ λ€μ΄κ° μ μλ€. μ΄λ κ² νλ©΄ finally λ₯Ό μ¨μ close() κΉμ§ ν΄μΌνλ νλμ½λ©μ νμ§ μκ³ μμ±ν μ μλ€.
AutoCloseable λ₯Ό μμνκ³ μλ μ°κ²°(Connection) SQLμ€ν(Statement) SQLμ€ννκ³ λμ¨ λ°μ΄ν°λ² μ΄μ€ κ²°κ³Ό κ°μ λ°νν(ResultSet) μμλλ‘ μ§ννλ€.
'κ°λ° μ§μ, μ€ν¬λ¦½νΈ > JPA & JDBC' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
Caused by: java.sql.SQLSyntaxErrorException: Table 'test8.cardlist' doesn't exist -μμ±μ€- (1) | 2024.04.01 |
---|---|
JDBC (0) | 2024.01.20 |
MySQL μλͺ»λ λ¬Έλ²μ μμ±νλ©΄ λ°μνλ μλ¬ (0) | 2024.01.18 |
"select * from todo where id = ?" μ¬μ©λ² (1) | 2024.01.18 |
Connector j μ μ©νκΈ° (1) | 2024.01.16 |
λκΈ