用c3p0实现Apache—DBUtils框架的Dao层源码
用c3p0实现Apache—DBUtils框架的Dao层源码
分类: 课堂随笔 2011-11-22 20:43 484人阅读 评论(0) 收藏 举报
用c3p0实现Apache—DBUtils框架的Dao层源码
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ArrayHandler;
import org.apache.commons.dbutils.handlers.ArrayListHandler;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.MapListHandler;
import com.hbsi.domain.User;
import com.hbsi.utils.DBManager_c3p0;
public class UserDaoImpl {
// 插入操作
public void insert() {
// 得到数据库连接池对象
QueryRunner runner = newQueryRunner(DBManager_c3p0.getDataSource());
String sql = "insertinto users(name,password) values('liop','8988')";
try {
runner.update(sql);
} catch (SQLException e){
// TODOAuto-generated catch block
e.printStackTrace();
}
}
// 删除操作
public void delete() {
QueryRunner runner = newQueryRunner(DBManager_c3p0.getDataSource());
String sql = "deletefrom users where id=1";
try {
runner.update(sql);
} catch (SQLException e){
// TODOAuto-generated catch block
e.printStackTrace();
}
}
// 更新操作
public void update() {
QueryRunner runner = newQueryRunner(DBManager_c3p0.getDataSource());
String sql = "updateusers set name='老王',password=222 where id=3";
try {
runner.update(sql);
} catch (SQLException e){
// TODOAuto-gen