日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
分步詳解 如何在iBatis中調(diào)用存儲(chǔ)過程

通過iBatis我們可以在數(shù)據(jù)庫表中執(zhí)行內(nèi)嵌的insert , delete, update SQL命令。本文中你將看到如何在iBatis中調(diào)用存儲(chǔ)過程.

成都創(chuàng)新互聯(lián)公司成立于2013年,我們提供高端網(wǎng)站建設(shè)、成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)公司、網(wǎng)站定制、全網(wǎng)整合營銷推廣成都小程序開發(fā)、微信公眾號(hào)開發(fā)、成都網(wǎng)站營銷服務(wù),提供專業(yè)營銷思路、內(nèi)容策劃、視覺設(shè)計(jì)、程序開發(fā)來完成項(xiàng)目落地,為成都廣告制作企業(yè)提供源源不斷的流量和訂單咨詢。

我們使用MySQL數(shù)據(jù)庫,并且使用和上一個(gè)例子中一樣的Contact表.

我們?cè)跀?shù)據(jù)庫"vin"中創(chuàng)建了一個(gè)叫showData()的存儲(chǔ)過程,它將顯示Contract表中的所有的contact信息.為了創(chuàng)建存儲(chǔ)過程,我們打開MySQL并創(chuàng)建如下定義的過程 :

 
 
 
 
  1. DELIMITER $$  DROP  PROCEDURE  IF EXISTS `vin`.`showData`$$  CREATE  PROCEDURE  `vin`.`showData`()BEGINselect *  from  Contact; END$$ DELIMITER ; 

"Contact.java"和"SqlMapConfig.xml"與上一個(gè)例子中的是一樣的 :

 
 
 
 
  1. public class Contact {  private String firstName;  
  2.  private String lastName;     private String email;   
  3.  private int id;   public Contact() {}   
  4.  public Contact(    String firstName,    String lastName,    String email) {    this.firstName = firstName;  
  5.   this.lastName = lastName;    this.email = email;    }   
  6.  public String getEmail() {    return email;  } 
  7.  public void setEmail(String email) {    this.email = email;  }
  8.   public String getFirstName() {    return firstName;  } 
  9.  public void setFirstName(String firstName) {    this.firstName = firstName;  } 
  10.  public int getId() {    return id;  }  public void setId(int id) {    this.id = id;  }  
  11. public String getLastName() {    return lastName;  }  public void setLastName(String lastName) {    this.lastName = lastName;  } } 

SqlMapConfig.xml

 
 
 
 
  1. "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">      
  2.           
  3.         
  4.          
  5.          
  6.           
  7.            
  8.     
  9.         
  10.    

我們只需修改"Contact.xml"并使用 標(biāo)簽來在iBatis中調(diào)用存儲(chǔ)過程

 
 
 
 
  1.     
  2.    { call showData() }  

上面幾行代碼調(diào)用了存儲(chǔ)過程并集合了contract表.下面是Contact.xml的代碼 :

 
 
 
 
  1. "http://ibatis.apache.org/dtd/sql-map-2.dtd">
  2.   
  3.       
  4.         
  5.       { call showData()}     

現(xiàn)在我們可以這樣在iBatis中調(diào)用存儲(chǔ)過程 :

sqlMap.queryForList("Contact.storedInfo",null); "sqlMap"是SqlMapClient類的一個(gè)對(duì)象. IbatisStoredProcedure.java的代碼如下 :

 
 
 
 
  1. import com.ibatis.common.resources.Resources;
  2. import com.ibatis.sqlmap.client.SqlMapClient;
  3. import com.ibatis.sqlmap.client.SqlMapClientBuilder;
  4. import java.io.*;import java.sql.SQLException;
  5. import java.util.*; 
  6. public class IbatisStoredProcedure{  public static void main(String[] args)     
  7.   throws IOException,SQLException{        Reader reader =       Resources.getResourceAsReader("SqlMapConfig.xml");      
  8. SqlMapClient sqlMap =       SqlMapClientBuilder.buildSqlMapClient(reader);      System.out.println("All Contacts");    
  9.   List contacts = (List)   
  10.      sqlMap.queryForList("Contact.storedInfo",null);    
  11.     Contact contact = null;    
  12.   for (Contact c : contacts) {      System.out.print("  " + c.getId());    
  13.   System.out.print("  " + c.getFirstName()); 
  14.      System.out.print("  " + c.getLastName());     
  15.  System.out.print("  " + c.getEmail());   
  16.      contact = c;     
  17.   System.out.println("");      }      }}  

請(qǐng)依照如下步驟執(zhí)行在iBatis中調(diào)用存儲(chǔ)過程 :

  創(chuàng)建Contact.xml和SqlMapConfig.xml

  創(chuàng)建Contact.java并將其編譯

  創(chuàng)建IbatisStoredProcedure.java并將其編譯

  執(zhí)行IbatisStoredProcedure類文件,所有的Contract信息將在你的命令提示符下顯示 :

【編輯推薦】

  1. iBATIS教程之like語句的寫法淺析
  2. iBATIS應(yīng)用之SQLMap API編程淺析
  3. iBATIS入門程序六大步詳解
  4. iBATIS與Hibernate間的取舍
  5. iBATIS接口應(yīng)用的淺析

分享題目:分步詳解 如何在iBatis中調(diào)用存儲(chǔ)過程
文章來源:http://www.5511xx.com/article/cddpsgs.html