步驟一:新建立一個項目。
步驟二:爲該項目添加spring的應用環境。
添加對應的jar包
spring需要引用的jar包,可以參考地址:http://jinyanliang.iteye.com/blog/875437
步驟三:導入Ibatis的必須JAR包以及數據庫JAR包 ibatis.jar,導入proxool需要的jar包 proxool-0.9.1.jar;proxool-cglib.jar;
步驟四:創建dao接口和實現類;
package com.test.one.dao;
public interface StudentDao {
public void searchInfo();
public void getStudentById();
}
package com.test.one.dao;
import java.util.List;
import java.util.Map;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
public class StudentImpl implements StudentDao {
private SqlMapClientTemplate sqlMapClientTemplate;
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) {
this.sqlMapClientTemplate = sqlMapClientTemplate;
}
@SuppressWarnings("unchecked")
public void searchInfo() {
// TODO Auto-generated method stub
List<Map> listResult= sqlMapClientTemplate.queryForList("getAllStudent");
}
public void getStudentById() {
// TODO Auto-generated method stub
List<Map> listResult= sqlMapClientTemplate.queryForList("getStudentById");
System.out.println("111");
}
}
步驟五:新建相應的Bean的配置文件。如下:Student-sqlMap.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="GOOD_NUM_TYMH_PORTAL_CUSTOMER_INFORMATION">
<!-- 查詢操作 -->
<select id="getAllStudent" resultClass="java.util.HashMap">
SELECT * FROM portal_flowcard_check
</select>
<!-- 通過編號獲取信息 -->
<select id="getStudentById" resultClass="java.util.HashMap">
SELECT * FROM portal_orderbill where staff_nbr='18918936751'
</select>
</sqlMap>
步驟六:新建Ibatis的應用配置文件。sql-map-config.xml
<?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>
<!-- 通知spring到哪裏去尋找配置文件 -->
<sqlMap resource="com/test/one/sqlMap/Student-sqlMap.xml" />
</sqlMapConfig>
步驟七:修改spring的applicationContext.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"
default-autowire="byName">
<description>Spring公共配置文件</description>
<!-- spring的ibatis 配製 -->
<!-- JDBC數據源配置關閉,本地使用-->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>org.logicalcobwebs.proxool.ProxoolDriver</value>
</property>
<property name="url">
<value>proxool.proxool-jtwt</value>
</property>
</bean>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean" >
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="configLocation">
<value>WEB-INF/conf/sql-map-config.xml</value>
</property>
</bean>
<!-- 配置模板 -->
<bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate" >
<property name="sqlMapClient">
<ref bean="sqlMapClient" />
</property>
</bean>
<bean id="studentDAO" class="com.test.one.dao.StudentImpl" >
<property name="sqlMapClientTemplate">
<ref bean="sqlMapClientTemplate" />
</property>
</bean>
</beans>
步驟八:配置proxool配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!--
the proxool configuration can be embedded within your own
application's. Anything outside the "proxool" tag is ignored.
-->
<something-else-entirely>
<proxool>
<alias>dbname</alias> <!--數據源的別名-->
<driver-url>jdbc:oracle:thin:@127.0.0.1:1521:testdb</driver-url><!--url連接串-->
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class> <!--驅動類-->
<driver-properties>
<property name="user" value="username" /> <!--用戶名-->
<property name="password" value="password" /><!--密碼-->
</driver-properties>
<!--最大連接數(默認5個),超過了這個連接數,再有請求時,就排在隊列中等候,最大的等待請求數由maximum-new-connections決定 -->
<maximum-connection-count>100</maximum-connection-count>
<!--最小連接數(默認2個)-->
<minimum-connection-count>10</minimum-connection-count>
<!--proxool自動偵察各個連接狀態的時間間隔(毫秒),偵察到空閒的連接就馬上回收,超時的銷燬 默認30秒-->
<house-keeping-sleep-time>90000</house-keeping-sleep-time>
<!--沒有空閒連接可以分配而在隊列中等候的最大請求數,超過這個請求數的用戶連接就不會被接受-->
<maximum-new-connections>10</maximum-new-connections>
<!--最少保持的空閒連接數(默認2個)-->
<prototype-count>5</prototype-count>
<!--在使用之前測試-->
<test-before-use>true</test-before-use>
<!--用於保持連接的測試語句 -->
<house-keeping-test-sql>select sysdate from dual</house-keeping-test-sql>
</proxool>
</something-else-entirely>
步驟八:配置web配置文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- 注入Spring文件 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/conf/applicationContext.xml</param-value>
</context-param>
<!-- log4j 配置
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
-->
<!-- porxool 配置初始化servlet,在web容器加載的時候自動加載配置文件,如果不是web程序,這個部分就需要通過開發接口來初始化了 -->
<servlet>
<servlet-name>proxoolInitialServlet</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.configuration.ServletConfigurator</servlet-class>
<init-param>
<param-name>xmlFile</param-name>
<param-value>WEB-INF/config/proxool.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- porxool 監控配置 -->
<servlet>
<servlet-name>proxooladmin</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.admin.servlet.AdminServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>proxooladmin</servlet-name>
<url-pattern>/proxooladmin</url-pattern>
</servlet-mapping>
</web-app>
proxool 數據庫工具使用
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.