//applicationContext_dao.xml中配置
<bean id="jdbcTemplate"
class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
//要用到的类依赖jdbcTemplate
<bean id="NexusDao" class="com.wei.dao.NexusDao">
<property name="jdbcTemplate">
<ref bean="jdbcTemplate" />
</property>
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
//NexusDao类中
//buildid为要传入的值
String sql = "select * from Nexus where buildid=?";
this.jdbcTemplate.query(sql, new Object[]{buildid},
new RowCallbackHandler() {
public void processRow(java.sql.ResultSet rs) throws SQLException {
Nexus nexus = new Nexus();
nexus.setAreaid(rs.getLong("areaid"));
}
});
return this.getHibernateTemplate().find(sql);
<bean id="jdbcTemplate"
class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
//要用到的类依赖jdbcTemplate
<bean id="NexusDao" class="com.wei.dao.NexusDao">
<property name="jdbcTemplate">
<ref bean="jdbcTemplate" />
</property>
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
//NexusDao类中
//buildid为要传入的值
String sql = "select * from Nexus where buildid=?";
this.jdbcTemplate.query(sql, new Object[]{buildid},
new RowCallbackHandler() {
public void processRow(java.sql.ResultSet rs) throws SQLException {
Nexus nexus = new Nexus();
nexus.setAreaid(rs.getLong("areaid"));
}
});
return this.getHibernateTemplate().find(sql);