锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
]]>
package com.testidatis.sample;
import java.io.*;
import java.util.*;
public class User implements Serializable {
聽private String id;
聽private String pwd;
聽private String xb;
聽private String grqk;
聽public String getGrqk() {
聽聽return grqk;
聽}
聽public void setGrqk(String grqk) {
聽聽this.grqk = grqk;
聽}
聽public String getId() {
聽聽return id;
聽}
聽public void setId(String id) {
聽聽this.id = id;
聽}
聽public String getPwd() {
聽聽return pwd;
聽}
聽public void setPwd(String pwd) {
聽聽this.pwd = pwd;
聽}
聽public String getXb() {
聽聽return xb;
聽}
聽public void setXb(String xb) {
聽聽this.xb = xb;
聽}
}
##涓嬩竴姝ュ氨鏄疭QL MAP鐨勯厤緗枃浠訛紝涔熷啓涓涓渶綆鍗曠殑錛屽叾浠栧睘鎬у彲浠ュ弬鐓х綉涓婄殑鏁欑▼錛岀綉鍧鏄?/strong>
http://www.baidu.com
聽 鍜屄?
http://www.google.com
聽 榪炴帴鏁版嵁搴撶殑鍙傛暟鎴戠洿鎺ュ啓鍏ラ厤緗枃浠朵簡(jiǎn)錛屼篃鍙互鍐欏湪涓涓?.properties鐨勯厤緗枃浠朵腑銆備唬鐮佸涓嬶細(xì)
<?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="org.hsqldb.jdbcDriver"/>
聽聽聽<property name="JDBC.Driver" value="oracle.jdbc.driver.OracleDriver" />
聽聽聽<property name="JDBC.ConnectionURL" value="jdbc:oracle:thin:@192.168.1.90:1521:orcl" />
聽聽聽<property name="JDBC.Username" value="fortest" />
聽聽聽<property name="JDBC.Password" value="123" />
聽聽</dataSource>
聽聽</transactionManager>
聽聽<sqlMap resource="com/testidatis/sample/User.xml" />
</sqlMapConfig>
##絎笁姝ヤ簡(jiǎn)錛歋QL Map鐨勬槧灝勬枃浠?br />榪欎竴姝ユ病浠涔堝ソ璇寸殑錛岃窡鏅氱殑T-SQL璇彞寰堢被浼鹼紝緗戜笂鐪嬭祫鏂欏惂錛?br />浠g爜濡備笅錛?br /><?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 namespace="User">
聽<typeAlias alias="user" type="com.testidatis.sample.User" />
聽
聽<select id="getUser" parameterClass="java.lang.String" resultClass="user">
聽聽 select id,pwd,xb from t_user
聽聽 where id=#id#
聽</select>
聽
聽<update id="updateUser" parameterClass="user">
聽聽<![CDATA[
聽 update t_user
聽 set pwd=#pwd#,
聽聽聽聽聽 xb=#xb#
聽 where id=#id#
聽]]>
聽</update>
聽
聽<insert id="insertUser" parameterClass="user">
聽聽insert into t_user(id,pwd,xb) values(#id#,#pwd#,#xb#)
聽</insert>
聽
聽<delete id="deleteUser" parameterClass="java.lang.String">
聽聽delete from t_user where id=#id#
聽</delete>
</sqlMap>
##鏈鍚庝竴姝ワ細(xì)嫻嬭瘯鍜變滑鐨刬batis鍚?br />package com.testidatis.sample;
import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import com.ibatis.common.resources.Resources;
public class TestMain {
聽/**
聽 * @param args
聽 * @throws IOException
聽 * @throws SQLException
聽 */
聽public static void main(String[] args) throws IOException, SQLException {
聽聽
聽聽// TODO Auto-generated method stub
聽聽String resource="com/testidatis/sample/SqlMapConfig.xml";
聽聽Reader reader;
聽聽
聽聽reader=Resources.getResourceAsReader(resource);
聽聽//SqlMapClientBuilder xmlBuilder=new SqlMapClientBuilder();
聽聽聽
聽聽SqlMapClient sqlMap=SqlMapClientBuilder.buildSqlMapClient(reader);
聽聽 try{
聽聽聽sqlMap.startTransaction();
聽聽聽User user=new User();
聽聽聽user.setId("00100");
聽聽聽user.setPwd("Erica");
聽聽聽user.setXb("F");
聽聽聽sqlMap.insert("insertUser",user);
聽聽聽sqlMap.commitTransaction();
聽聽聽
聽聽聽}catch(Exception e){
聽聽聽聽System.out.println("榪炴帴鏁版嵁鍑洪敊");
聽聽聽}
聽聽聽finally{
聽聽聽聽sqlMap.endTransaction();
聽聽聽}
聽聽聽System.out.println("榪炴帴鏁版嵁搴撴垚鍔?);
聽聽}
}
鍏跺疄涔熸病浠涔堥毦鐨勶紝澶氱湅鏁欑▼灝監(jiān)K浜?jiǎn)锛?br />嫻嬭瘯綾諱腑鐨勯儴鍒嗕唬鐮佷篃鍙互灝佽涓涓嬶紝綆鍗曞伐鍘傛ā寮忓氨鍙互錛岃繑鍥炵被鍨嬶紵閭e綋鐒舵槸SqlMapClient鐨勪簡(jiǎn)錛屽懙鍛點(diǎn)?br />鏁版嵁搴撶殑榪炴帴Oracle錛屽叾浠栨暟鎹簱鏂規(guī)硶閮芥槸澶у悓灝忓紓銆?br />鏍規(guī)嵁鎴戠殑JavaBean鑷繁寤轟釜琛ㄦ祴璇曞幓鍚с?/strong>