JDBC
ADO.NET
객체 관계 매퍼
하이버네이트
iBATIS // SQL mapper
expect that you’re using a real relational database that supports transactions and relatively typical SQL and stored procedure semantics
query를 코드와 분리
1. 커넥션을 얻는다.
2. 파라미터를 설정한다.
3. 쿼리 구문을 실행한다.
4. 결과를 가져온다.
5. 모든 자원을 닫는다.
sqlMapClient
.queryForObject()
.queryForList()
.queryForMap()
e.g. Address address = (Address) sqlMap.queryForObject("getAddress", new Integer(5));
매핑 구문의 타입
<select />
<insert />
<update />
<delete />
<procedure />
<statement />
<sql />
<include />
<dynamic />
.prepend
.open
.close
<isNull />
.property // 빈(파라미터 객체?)의 속성
<isNotNull />
.prepend
.property
<isPropertyAvailable />
.property
<isNotPropertyAvailable />
.property
<isEqual />
.prepend
.property
.compareValue|.compareProperty
<isGreaterThan />
.property
.compareValue|.compareProperty
<isGreaterEqual />
.property
.compareValue|.compareProperty
<isLessThan />
.property
.compareValue|.compareProperty
<isLessEqual />
.property
.compareValue|.compareProperty
<iterate />
.property
.open
.close
.conjunction
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>
<transactionManager type="JDBC" >
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/>
<property name="JDBC.ConnectionURL" value="jdbc:mysql://localhost/..."/>
<property name="JDBC.Username" value=".."/>
<property name="JDBC.Password" value=".."/>
</dataSource>
</transactionManager>
<sqlMap resource="SqlMap.xml" />
</sqlMapConfig>
접기 SqlMap.xml
더보기 접기
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap>
<select id="getAllUsers" parameterClass="string" resultClass="hashmap">
SELECT * FROM USER_ACCOUNT WHERE GROUPNAME = #groupName#
</select>
</sqlMap>
접기 더보기 접기
import com.ibatis.sqlmap.client.*;
import com.ibatis.common.resources.Resources;
import java.io.Reader;
import java.util.List;
public class Main {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
String resource = "SqlMapConfig.xml";
Reader reader = Resources.getResourceAsReader(resource);
SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
List list = sqlMap.queryForList("getAllUsers", "EMPLOYEE");
for(int i=0; i < list.size(); i++) {
.. list.get(i) ..
}
}
}
접기