spring中的jdbc訪問類JdbcTemplate使用

字號(hào):

在不使用hibernate的情況下,使用它來操作數(shù)據(jù)庫也不錯(cuò),至少不用自己去封裝了。java里的東西就是多。
    在applicationContext.xml中的配置
        class="org.springframework.jdbc.core.JdbcTemplate">
    
    
    

    

    在DAO層的使用
    public List getBranchById(String branchId) {
    String sql = "select * from dept where deptid=’" + branchId + "’";
    try {
    return jdbcTemplate.queryForList(sql);
    } catch (DataAccessException e) {
    throw e;
    }
    }