메뉴 건너뛰기

조회 수 3948 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.ibatis.sqlmap.client.SqlMapClient" %>
<%@ page import="java.util.List" %>
<%@ page import="xf.common.*" %>
<%@ page import="xf.modules.sample.sampleDTO" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="ko" xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta content="no" http-equiv="imagetoolbar"/>
<title>iBatis 동적 Connection Sample</title>
</head>
<body>
<form id="list_form" name="list_form">
<table border="1" cellspacing="0" cellpadding="0" width="100%">
  <colgroup>
    <col width="80" />
    <col width="*" />
  </colgroup>
  <thead>
    <tr>
      <th scope="col">인덱스</th>
      <th scope="col">타이틀</th>
    </tr>
  </thead>
  <tbody>
  <%
  // SqlMapConfig Connection : WEB-INF/Classes 하위 경로 부터
  // 동적으로 SqlMapConfig 로드함.
  String resource = "xf/modules/sample/SqlMapConfig.xml";
  SqlMapClient conn = SqlMapConfig(resource).getSqlMapInstance();
 
  // 아래부터는 예제로 작성됨...
  // getSample statement call
  List result = conn.queryForList("getSample",null);
  // for begin
  for(int i = 0; i < result.size(); i ++) {
    // sampleDTO bean
    sampleDTO sample = (sampleDTO) result.get(i);
    int idx = sample.getIdx();
    String title = sample.getTitle();
  %>
  <tr>
    <td><%=idx%></td>
    <td><a href="./sample.update.jsp?idx=<%=idx%>"><%=title%></a></td>
  </tr>
  <% } %>
  </tbody>
  <tfoot>
    <tr>
      <td colspan="2"><a href="./sample.insert.jsp">등록</a></td>
    </tr>
  </tfoot>
</table>
</form>
</body>
</html>


iBATIS에서 SqlMapConfig.xml 에 맵을 모두 설정하지 않고, 분할하여 관리할 수 있게 수정함.
하나의 iBatis 에서 여러 DBMS 커넥에 가능하며, 하나의 맵 오류로 인해 전체에 영향을 미치지 않게 되었다.


Java Source : SqlMapConfig.java

package xf.common;
 
/*
'// Connection
'// programmed by 최석균
'// http://syaku.tistory.com
*/
 
import java.io.Reader;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class SqlMapConfig {
  private static final SqlMapClient sqlMap;
  private static String resource = "SqlMapConfig.xml";

  public SqlMapConfig() {
  }

  public SqlMapConfig(String resource) {
    this.resource = resource;
  }

  static {
    try {
      Reader reader = Resources.getResourceAsReader (resource);
      sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException ("Error initializing SqlConfig class. Cause: " + e);
    }
  }

  public static SqlMapClient getSqlMapInstance() {
    return sqlMap;
  }

}


XML Source : SqlMapConfig.xml


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
 <properties resource="SqlMapConfig.properties" />
 <settings
  cacheModelsEnabled="true"
  enhancementEnabled="true"
  lazyLoadingEnabled="true"
  maxRequests="32"
  maxSessions="10"
  maxTransactions="5"
  useStatementNamespaces="false"
 />
 <typeAlias alias="order" type="testdomain.Order"/>
 <transactionManager type="JDBC" >
  <!--
  <dataSource type="SIMPLE">
   <property name="JDBC.Driver" value="${driver}"/>
   <property name="JDBC.ConnectionURL" value="${url}"/>
   <property name="JDBC.Username" value="${username}"/>
   <property name="JDBC.Password" value="${password}"/>
  </dataSource>
  -->
     <dataSource type="JNDI">
         <property name="DataSource" value="java:${data_source_name}" />
     </dataSource>
 </transactionManager>
 
  <sqlMap resource="xf/modules/sample/sampleDAO.xml"/>
</sqlMapConfig>


Example Source




List of Articles
번호 제목 날짜 조회 수
111 Spring Boot 프로젝트 생성 file 2016.09.02 4160
110 war로 묶지 않아도 컴파일된 소스 위치 확인하기 file 2016.08.29 4116
109 Database Connections 생성하기 (오라클) file 2016.08.29 4072
108 jquery 스크롤(scroll) 따라다니는 배너 레이어 / 위로 버튼 / 화면 상단으로 이동 / scroll layer 이벤트 file 2017.07.05 4057
107 [자바(스프링&mybatis&jsp) 프로젝트 & 아파치 &톰켓 연동 ]9. 이클립스 압타나 플러그인 설치 file 2016.08.18 4012
106 프로젝트 & 아파치 &톰켓 연동 ]1. 폴더 만들기 file 2016.08.18 3983
105 변수의 종류 2016.09.13 3978
104 [자바(스프링&mybatis&jsp) 프로젝트 & 아파치 &톰켓 연동 ]11. 이클립스 프로젝트 생성 file 2016.08.18 3972
» iBATIS 동적으로 맵핑하기 2016.12.09 3948
102 개인정보 마스킹처리 (휴대폰번호, 이메일) 2018.06.26 3941
101 로그인 컴포넌트 설치시 뷰 생성 에러 해결방법 (ORA-01031: 권한이 불충분합니다) file 2016.08.29 3874
100 Select statements cannot be executed as an update. 에러 해결방법 file 2016.08.29 3845
99 [자바(스프링&mybatis&jsp) 프로젝트 & 아파치 &톰켓 연동 ] 이클립스 프로젝트 생성 순서07.commons-collection 설치 file 2016.08.18 3845
98 새로 만든 모듈의 iBatis 쿼리를 새로운 xml 파일에 만들고 싶다면 이렇게 하자. file 2016.08.29 3773
97 static멤버와 관련된 예제 2016.09.21 3768
96 바이트 기반의 스트림 file 2016.09.13 3763
95 [자바(스프링&mybatis&jsp) 프로젝트 & 아파치 &톰켓 연동]3. 이클립스 설치 file 2016.08.18 3756
94 클래스 메서드와 인스턴스 메서드 2016.09.13 3720
93 BigDecimal타입의 사칙연산 2016.12.22 3713
92 JAR 파일 2016.09.19 3713
Board Pagination Prev 1 2 3 4 5 6 7 8 Next
/ 8

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved