;for(Actor actor2:actors){System.out.println("actor2"+actor2);}return rowCount;}}

package com.tfy.spring.jdbc;import java.sql.ResultSet;import java.sql.SQLException;import java.util.Collection;import java.util.List;import org.springframework.jdbc.core.JdbcTemplate;import org.springframework.jdbc.core.RowMapper;public class ClassesDaoImpl implements ClassesDao {private JdbcTemplate jdbcTemplate;public JdbcTemplate getJdbcTemplate() {return jdbcTemplate;}public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {this.jdbcTemplate = jdbcTemplate;}@Overridepublic void saveClasses() {this.jdbcTemplate.execute("insert into classes values('xiaofang',1)");}@Overridepublic int queryClasses() {int rowCount = this.jdbcTemplate.queryForInt("select count(0) from classes");System.out.println("rowCount==="+rowCount);int countOfActorsNamedJoe = this.jdbcTemplate.queryForInt( "select count(0) from classes where name = ?", new Object[]{"xiaofangas"});System.out.println("countOfActorsNamedJoe=="+countOfActorsNamedJoe);String surname = (String) this.jdbcTemplate.queryForObject( "select name from classes where id = ?", new Object[]{new Integer(1)}, String.class);System.out.println("surname=="+surname);//-----------------------------------------------------------Actor actor = (Actor) this.jdbcTemplate.queryForObject( "select name, id from classes where id = ?", new Object[]{new Integer(1)}, new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { Actor actor = new Actor(); actor.setId(rs.getInt(2)); actor.setName(rs.getString("name")); return actor; } });System.out.println("actor=="+actor);List actors = this.jdbcTemplate.query( "select id,name from classes", new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { Actor actor = new Actor(); actor.setId(2); actor.setName(rs.getString("name")); return actor; } });for(Actor actor2:actors){System.out.println("actor2"+actor2);}return rowCount;}}

你可能感兴趣的:(;for(Actor actor2:actors){System.out.println("actor2"+actor2);}return rowCount;}})