You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
git-test1/TypeDao

43 lines
1.7 KiB

package dao;
import model.Type;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import utils.DataSourceUtils;
import java.sql.SQLException;
import java.util.List;
public class TypeDao
{
public List<Type> GetAllType() throws SQLException {
QueryRunner r=new QueryRunner(DataSourceUtils.getDataSource());
String sql="select * from type";
return r.query(sql,new BeanListHandler<Type>(Type.class));
}
public Type selectTypeNameByID(int typeid) throws SQLException {
QueryRunner r=new QueryRunner(DataSourceUtils.getDataSource());
String sql="select * from type where id=?";
return r.query(sql,new BeanHandler<Type>(Type.class),typeid);
}
public Type select(int id) throws SQLException {
QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());
String sql = "select * from type where id = ?";
return r.query(sql, new BeanHandler<Type>(Type.class),id);
}
public void insert(Type t) throws SQLException {
QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());
String sql = "insert into type(name) values(?)";
r.update(sql,t.getName());
}
public void update(Type t) throws SQLException {
QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());
String sql = "update type set name=? where id = ?";
r.update(sql,t.getName(),t.getId());
}
public void delete(int id) throws SQLException {
QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());
String sql = "delete from type where id = ?";
r.update(sql,id);
}
}