在JdbcTemplate类中还提供了大量的query()方法来处理各种对数据库的查询操作
下面通过一个案例来演示query方法的使用
1、向数据表account中插入几条数据,插入后的数据如下所示:
2、在AccountDao中创建一个通过id查找单个账户,和查找所有账户的方法,代码如下所示:
package com.itheima.jdbc;
import java.util.List;
public interface AccountDao {
//添加
public int addAccount(Account account) ;
//更新
public int upAccount(Account account) ;
//删除
public int deleteAccount(int id) ;
//通过id查询单个账号
public Account findAccount(int id);
//查询所有账号
public List<Account> findAccount();
}
3、在AccountDao的实现类AccountDaoImpl中,实现接口中的方法,并使用query()方法分别进行查询,其代码如下所示:
//通过id查询账户数据信息
public Account findAccountById(int id) {
String sql= "selec