iBATIS 搭建成功

1 下載所需要的包

http://www.mybatis.org/

2 導入包

ibatis-2.3.0.677.jar


3  編寫 SQLMapConfig.xml 位置 src下面

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

<!DOCTYPE sqlMapConfig
 PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
 "http://www.ibatis.com/dtd/sql-map-config-2.dtd">

<sqlMapConfig>
    
 <settings
  cacheModelsEnabled="true"
  enhancementEnabled="true"
  lazyLoadingEnabled="true"
  maxRequests="32"
  maxSessions="10"
  maxTransactions="5"
  useStatementNamespaces="false"
 />
 
 <transactionManager type="JDBC" >
  <dataSource type="SIMPLE">
   <property name="JDBC.Driver" value="oracle.jdbc.driver.OracleDriver"/>
   <property name="JDBC.ConnectionURL" value="jdbc:oracle:thin:@localhost:1521:xe"/>
   <property name="JDBC.Username" value="scott2100"/>
   <property name="JDBC.Password" value="tiger"/>
  </dataSource>
 </transactionManager>

 <sqlMap resource="movieUser/movieUser.xml" />
</sqlMapConfig>

4 驗證

package SqlMapClient;

import com.ibatis.sqlmap.client.*;
import com.ibatis.common.resources.*;

import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.List;

import movieUser.moive_user;

public class test {
 
 public static void main(String args[]) {

  try {
   com.ibatis.sqlmap.client.SqlMapClient sqlMap = null;
   String resource = "SQLMapConfig.xml";
   Reader reader = Resources.getResourceAsReader (resource);
   sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
   moive_user person =(moive_user)sqlMap.queryForObject("getMovieUser",new Integer(0));
   System.out.println(person.getUserName());
  
  } catch (IOException e) {
   e.printStackTrace();
  } catch (SQLException e1){
   e1.printStackTrace();
  }
 }


}

5 結果


iBATIS 成功了

加油 !!!



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章