컴퓨터공학/Java
CS> JDBC connection 단계
Milhouse Mussolini Van Houten
2021. 7. 5. 23:16
JDBC(Java Database Connectivity)
데이터베이스에 연결되어서 여러 쿼리를 실행할 수 있는 Java api를 의미한다.
jdbc는 특정 데이터베이스와는 상관없이 일반적인 industry standard한 방법(RDBMS) 을 이용한다.
JDBC Steps
Load the driver
Establish the Connection
Create a Statement
Execute a query
Process the result as ResultSet
Close the connection
Connection을 끄지 않고 계속 생성하면 Maximum open cursors exceeds 라는 에러가 떠서 자바 어플의 메모리가 부족할 수 있다.
정리
java API to connect and execute query with databases
JDBC란 데이터베이스를 연결하고 쿼리를 실행하는 api이다.
Load driver & Establish the connection
드라이버를 로딩하고 커넥션을 생성하고
create a statement & execute a query
생성된 커넥션으로 statement를 만들고 query를 statement를 이용하여 실행한다.
process the result as ResultSet
ResultSet 객체를 while 문을 이용하여 한 줄 씩 처리하고
Close the connection
닫는다.