목록Backend/JDBC (5)
개발 무지렁이

𐂂 Mapper문서 쿼리를 작성해놓은 문서 📜 sqlmapper형식.xml 🦉 mapper namespace 각각의 mapper를 유일하게 만들어주는 이름공간 📜 custmapper.xml SELECT * FROM cust WHERE id=#{id} SELECT * FROM cust INSERT INTO cust VALUES (#{id}, #{pwd}, #{name}) UPDATE TABLE cust SET password=#{password}, name=#{name}, WHERE id=#{id} DELETE FROM cust WHERE id=#{id} ➼ 🦔 parameter로 전달되는 데이터 처리 #{ }: PreparedStatement방식, ' '로 묶어서 매핑 ${ }: Statement방식, ..

𐂂 ORM (Object Relation Mapping) framework, MyBatis DAO -(위임)-> Mybatis -(조작)-> JDBC API (org.apache.ibatis 패키지에서 MyBatis framework 라이브러리 제공) ⚠️ 위임할 때 parameter와 result만 결정해주면 알아서 조작해준다. ⚠️ 내부구조가 PreparedStatement로 동작 🎯 목적: - JDBC 코드 및 매개변수의 중복작업을 제거 - 자바 코드와 SQL 쿼리의 분리로 간결화 - 복잡한 쿼리 작성 가능 - join 결과에 대한 쉬운 객체 바인딩 📜 mybatis.xml MyBatis 환경설정 문서 📜 dbInfo.properties url=jdbc:mysql://localhost:3306/sh..

DBCP WAS(Tomcat)가 이미 다 만들어 제공 일정량의 커넥션을 미리 확보 (Pool⛱️에 저장) 사용자와의 연결이 종료되면 Pool⛱️에 반환하여 보관한다. [webapp/META-INF/context.xml] [DBManager.java] public class DBManager { private static DataSource ds; /** * 로드 */ static { try { Context initContext = new InitialContext(); Context envContext = (Context)initContext.lookup("java:/comp/env"); ds = (DataSource)envContext.lookup("jdbc/myoracle"); } catch(Exc..

DBManager [DBManager.java] public class DBManager { /** * 로드 **/ static { try { Class.forName(DBProperties.DRIVER_NAME); } catch(ClassNotFoundException e) { e.printStackTrace(); } } /** * 연결 **/ public static Connection getConnection() throws SQLException { return DriverManager.getConnection(DBProperties.URL, DBProperties.USER_ID, DBProperties.USER_PASS); } /** * 닫기(DML 전용) **/ public static voi..

JDBC(Java DataBase Connectivity) Java와 DB를 연동 🚀 단계 1) 로드: 연동하려는 DB제품(벤더)를 선택하는 것, Driver가 필요하다(~.jar) (만약 Driver를 못찾으면 ClassNotFoundException 발생) 2) 연결: 로드된 DB에 접속, URL(host name, port, SID), ID, Password를 이용해서 연결객체를 얻어오는 과정 3) 실행: CRUD 작업 4) 닫기: 사용된 객체를 반납 ⚠️ 커넥션(Connection)은 절대로 공유하면 안된다.(1커넥션 == 1트랜잭션) ⚠️ 1)은 변하지 않으니, 딱 한 번만❗1) 로드 - ~.jar 필요하다 Class.forName("Oracle: oracle.jdbc.driver.OracleD..