달력

06

« 2016/06 »

  •  
  •  
  •  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  •  
  •  

'2016/06'에 해당되는 글 1

  1. 2016.06.12 mybatis3 sample
2016.06.12 22:14

mybatis3 sample Developer/API2016.06.12 22:14

스프링에서 xml 처리하지않고 직접 xml 을 호출하면서 처리하는 예제.

인터넷이 되지않는 프로젝트에서 사용하려고 기록한다.


java 부분.

String resource = "mybatis-config.xml";

InputStream inputStream = null;

try {

inputStream = Resources.getResourceAsStream(resource);

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

SqlSession session = sqlSessionFactory.openSession();

 

List<HashMap> sss = session.selectList("testman.selectTest");

for (int a = 0; a < sss.size() ; a ++)

{

HashMap res = sss.get(a);

System.out.println("=====>" + res.get("ID"));

}


mybatis-config.xml

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE configuration

  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"

  "http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>

  <environments default="development">

    <environment id="development">

      <transactionManager type="JDBC"/>

      <dataSource type="POOLED">

        <property name="driver" value="oracle.jdbc.driver.OracleDriver"/>

        <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl"/>

        <property name="username" value="user"/>

        <property name="password" value="user"/>

      </dataSource>

    </environment>

  </environments>

  <mappers>

    <mapper resource="test.xml"/>

  </mappers>

</configuration>


mapper xml ( test.xml )

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE mapper

  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"

  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="testman">

  <select id="selectTest" resultType="hashmap">

    SELECT *FROM TTT

  </select>

</mapper>

저작자 표시
신고

'Developer > API' 카테고리의 다른 글

mybatis3 sample  (0) 2016.06.12
Apache POI - Excel 넓이  (0) 2013.10.02
Posted by ORACLE,DBA,BIG,DATA,JAVA 흑풍전설