文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>spring jdbctemplete应用

spring jdbctemplete应用

时间:2010-08-28  来源:夜色狼

<?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:context="http://www.springframework.org/schema/context"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-2.5.xsd">

 <bean id="userDAO" class="com.xxxxx.dao.BaseDAOImp">
  <property name="jdbcTemplate">
   <ref bean="jdbcTemplate" />
  </property>
  <property name="tableName" value="users"></property>
  <property name="objectClass" value="com.xxxxx.admin.vo.xxx"></property>
  <property name="keyColumn" value="id"></property>
 </bean>

 <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
  <constructor-arg>
   <ref bean="datasource" />
  </constructor-arg>
 </bean>
 <bean id="datasource"
  class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
  <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:xxxx" />
  <property name="username" value="xxxx" />
  <property name="password" value="xxxx" />
 </bean>
</beans>

 

就用:

 

 

BaseDAO userDAO = null;
  try {

    userDAO = (BaseDAO) xxx.getBeanFactory().getBean("userDAO");
  } catch (Exception e) {
   e.printStackTrace();
  }

  // find all
  List list = userDAO.findAll();
  System.out.println("user count: " + list.size()
    + ((UserVO) list.get(0)).getName());
  

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载