cn.itcast.bbs.dao.TypeDao.java Source code

Java tutorial

Introduction

Here is the source code for cn.itcast.bbs.dao.TypeDao.java

Source

/**
 * @(#)TypeDao.java, 2015107. 
 * 
 * Copyright 2015 Yodao, Inc. All rights reserved.
 * YODAO PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package cn.itcast.bbs.dao;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import cn.itcast.bbs.domain.Type;
import cn.itcast.bbs.util.JdbcUtil;

/**
 * ?Dao
 * @author Administrator
 *
 */
public class TypeDao {
    /*
     * ?
     */
    public List<Type> findAllType() throws SQLException {
        List<Type> typeList = null;
        QueryRunner runner = new QueryRunner(JdbcUtil.getDataSource());
        String sql = "select *from type;";
        typeList = runner.query(sql, new BeanListHandler(Type.class));
        return typeList;
    }

    /*
     * 
     */
    public void updateTypeClick(int id) throws SQLException {
        QueryRunner runner = new QueryRunner(JdbcUtil.getDataSource());
        String sql = "update type set click = click +1 where id = ?;";
        runner.update(sql, id);
    }

    /*
     * ?id?
     */
    public Type findTypeById(int id) throws SQLException {
        QueryRunner runner = new QueryRunner(JdbcUtil.getDataSource());
        String sql = "select *from type where id=?;";
        Type type = runner.query(sql, new BeanHandler(Type.class), id);
        return type;
    }

    /*
     * ?id?
     */
    public void deleteTypeById(int typeId) throws SQLException {
        QueryRunner runner = new QueryRunner();
        String sql = "delete from type where id = ?;";
        runner.update(JdbcUtil.getConnection(), sql, typeId);
    }
}