<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="username" value="sa" />
<property name="password" value="" />
<property name="url" value="jdbc:hsqldb:hsql://localhost:9001" />
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
ListableBeanFactory cbf = new ClassPathXmlApplicationContext("ac1.xml");
JdbcTemplate jt = (JdbcTemplate) cbf.getBean("jdbcTemplate");
List rsList = jt.queryForList("select * from pets");
//////////////////// 首先取得list
for(Iterator iterator = rsList.iterator();iterator.hasNext() ;){
//////////////////////////////将所有的list迭代出来
System.out.println(iterator.next());
}
- List rows = jdbcTemplate.queryForList("SELECT * FROM USER");
- Iterator it = rows.iterator();
- while(it.hasNext()) {
- Map userMap = (Map) it.next();
- System.out.print(userMap.get("user_id") + "\t");
- System.out.print(userMap.get("name") + "\t");
- System.out.print(userMap.get("sex") + "\t");
- System.out.println(userMap.get("age") + "\t");
- }
大盘预测
国富论
posted on 2007-09-06 17:50
华梦行 阅读(424)
评论(0) 编辑 收藏 所属分类:
Spring