DB연결
-
[JSP] MyBatis 적용_2(어노테이션 없이)JAVA/ORM 2024. 7. 30. 18:56
HTML 삽입미리보기할 수 없는 소스 https://hi-hahahoho.tistory.com/93저번 글에서는 configuration.xml과 sqlMapConfig.java 설정을 자세히 봤다. 이번에는 DataMapper.xml과 DAO간 어떻게 사용되는지 정리하겠다. jsp와 같은 앞단은 특별히 달라지는 것은 없다. ✔ DataDao⌨ SqlSessionMyBatis에서 데이터베이스와 실제 세션(sql 쿼리 실행을 준비)을 나타내는 객체이다. SQL 실행 및 트랜잭션 관리를 담당한다. openSession() 메서드를 호출하여 기본 세션을 열고 작업이 끝나면 해당 객체를 해제한다. 🔦 MyBatis는 List 자료구조를 반환한다. 여러 행을 조회할때, 해당 테이블의 모든 행을 조회하고 각 행을 ..
-
Ajax 사용, DB 읽어와서 웹브라우저에 보이기(레거시 방식 jsp)Front/js 2024. 7. 10. 14:25
▤ 목차" data-ke-type="html">HTML 삽입미리보기할 수 없는 소스 ✔ DB연결DB에 있는 데이터를 web브라우저에 보이려고 한다.DB의 데이터를 가져오기 위해서는 jsp를 사용해야한다. 데이터 테이블은 아래와 같다. ⌨ jsp 파일JDBC로 연결{"sangpum":[]}jsp는 안에 java를 사용한다.그 밖은 html소스를 사용한다. 위의 코드는 java를 사용해서 DB를 연결하는 코드이다.우선 프린트가 잘되는지 확인해보기위해 out.print(rs.getString("sang"));이 코드를 찍어봤다. 데이터베이스와 잘 연결되었음을 알 수 있다. 그럼 각 데이터를 추출해보자. String result = ""; while(rs.next()){ result +="{"; re..