ibatis跟着走
2007-11-07 19:49
190 查看
google_ad_client = "pub-5033576919944123";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
//2007-10-24: csdn.blog
google_ad_channel = "8548491739";
第一步:加jar包: 包括ibatis的包和数据库的驱动包.
第二步:写配置,包括xml还有属性文件,如下
ibatis.xml(名字可以改的)
<?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>
<properties resource="ibatis.properties" />
<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="${driver}" />
<property name="JDBC.ConnectionURL" value="${url}" />
<property name="JDBC.Username" value="${username}" />
<property name="JDBC.Password" value="${password}" />
</dataSource>
</transactionManager>
<sqlMap resource="wtc/ibatis/bi.xml" />
</sqlMapConfig>
bi.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 namespace="wtc.ibatis">
<select id="query" resultClass="java.util.HashMap">
select * from tableName(你的tableName)
</select>
</sqlMap>
ibatis.properties(名字可以改,但相应的地方要改,看有背景色的地方)
## Oracle
driver=oracle.jdbc.driver.OracleDriver(改成你的驱动)
url=jdbc:oracle:thin:@10.20.30.83:1521:db(改成你的)
username=dbu(改成你的)
password=dbp(改成你的)
第三步:写个类可以获取SqlMapClient的类
package wtc.ibatis;
import java.io.IOException;
import java.io.Reader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
/**
* <p>
* @author wujy <br>
* @date 2007-11-5 <br>
*
*/
public class SqlMapClientHolder {
private static SqlMapClient sqlMapClient = null;
private static String defaultXml = "ibatis.xml";
private static Logger logger = LoggerFactory.getLogger(SqlMapClientHolder.class);
public static SqlMapClient getSqlMapClient(String resource) {
if (sqlMapClient == null){
if (resource == null){
resource = defaultXml;
}
Reader reader;
try {
reader = Resources.getResourceAsReader (resource);
sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader);
} catch (IOException e) {
logger.debug("读取xml错误", e);
}
}
return sqlMapClient;
}
public static SqlMapClient getSqlMapClient() {
return getSqlMapClient(defaultXml);
}
public void setSqlMapClient(SqlMapClient sqlMapClient) {
this.sqlMapClient = sqlMapClient;
}
}
完了,写个测试:
package wtc.ibatis;
import java.sql.SQLException;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* <p>
* @author wujy <br>
* @date 2007-11-5 <br>
*/
public class IbatisTest {
/**
* @throws java.lang.Exception
*
*/
@Before
public void setUp() throws Exception {
}
@Test
public final void testStartUp() {
try {
List list = SqlMapClientHolder.getSqlMapClient().queryForList("query");
System.out.println(list);
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* @throws java.lang.Exception
*
*/
@After
public void tearDown() throws Exception {
}
}
此乃最基础的.喜欢就看看.
给些网址:
eclipse的ibatis插件:http://ibatis.apache.org/tools/abator
www.ibatis.org
google_ad_client = "pub-5033576919944123";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
//2007-10-24: csdn.blog
google_ad_channel = "8548491739";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
//2007-10-24: csdn.blog
google_ad_channel = "8548491739";
第一步:加jar包: 包括ibatis的包和数据库的驱动包.
第二步:写配置,包括xml还有属性文件,如下
ibatis.xml(名字可以改的)
<?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>
<properties resource="ibatis.properties" />
<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="${driver}" />
<property name="JDBC.ConnectionURL" value="${url}" />
<property name="JDBC.Username" value="${username}" />
<property name="JDBC.Password" value="${password}" />
</dataSource>
</transactionManager>
<sqlMap resource="wtc/ibatis/bi.xml" />
</sqlMapConfig>
bi.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 namespace="wtc.ibatis">
<select id="query" resultClass="java.util.HashMap">
select * from tableName(你的tableName)
</select>
</sqlMap>
ibatis.properties(名字可以改,但相应的地方要改,看有背景色的地方)
## Oracle
driver=oracle.jdbc.driver.OracleDriver(改成你的驱动)
url=jdbc:oracle:thin:@10.20.30.83:1521:db(改成你的)
username=dbu(改成你的)
password=dbp(改成你的)
第三步:写个类可以获取SqlMapClient的类
package wtc.ibatis;
import java.io.IOException;
import java.io.Reader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
/**
* <p>
* @author wujy <br>
* @date 2007-11-5 <br>
*
*/
public class SqlMapClientHolder {
private static SqlMapClient sqlMapClient = null;
private static String defaultXml = "ibatis.xml";
private static Logger logger = LoggerFactory.getLogger(SqlMapClientHolder.class);
public static SqlMapClient getSqlMapClient(String resource) {
if (sqlMapClient == null){
if (resource == null){
resource = defaultXml;
}
Reader reader;
try {
reader = Resources.getResourceAsReader (resource);
sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader);
} catch (IOException e) {
logger.debug("读取xml错误", e);
}
}
return sqlMapClient;
}
public static SqlMapClient getSqlMapClient() {
return getSqlMapClient(defaultXml);
}
public void setSqlMapClient(SqlMapClient sqlMapClient) {
this.sqlMapClient = sqlMapClient;
}
}
完了,写个测试:
package wtc.ibatis;
import java.sql.SQLException;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* <p>
* @author wujy <br>
* @date 2007-11-5 <br>
*/
public class IbatisTest {
/**
* @throws java.lang.Exception
*
*/
@Before
public void setUp() throws Exception {
}
@Test
public final void testStartUp() {
try {
List list = SqlMapClientHolder.getSqlMapClient().queryForList("query");
System.out.println(list);
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* @throws java.lang.Exception
*
*/
@After
public void tearDown() throws Exception {
}
}
此乃最基础的.喜欢就看看.
给些网址:
eclipse的ibatis插件:http://ibatis.apache.org/tools/abator
www.ibatis.org
google_ad_client = "pub-5033576919944123";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
//2007-10-24: csdn.blog
google_ad_channel = "8548491739";
相关文章推荐
- 利用ibatis管理hql/sql
- Power Designer:如何在输入name的时候,让code不跟着变
- Spring+Ibatis集成开发实例!
- timer事件调用ibatis时异常,提示WebSessionStore: Could not obtain reference to HttpContext的解决
- iBatis 配置文件详解
- IBATIS SQLMAP模板
- ibatis 插入,返回自增id,批处理
- SSI对struts、spring、ibatis三者的整合过程
- 跟着Google,盘点2011
- ibatis: insert时调用外部参数,还有sql in的用法
- IBatis 入门教程
- 大城市 讲公平 讲逻辑 。。。。探索未知领域不拿着逻辑线怎么往前走。。。。。 结论:要跟着逻辑走,越高层越这样。。(至于,有些物理概念,反直观。。。人本身硬件有局限。)
- ibatis相关例子及注意事项
- ibatis命名空间
- ibatis和hibernnate区别
- ibatis3.06 + spring 3.06+velocity 整合的VSSI框架测试
- 跟着 伍逸 老师学GDI+ 之Pen属性
- struts2+spring+dwr+ibatis整合jar组合
- ibatis 查级联的多张表数据方法
- Ibatis处理空值,jdbcType