框架

框架分为:daomian、dao、utils、c3p0描述文件;(由于时间问题还未完毕,待更新!)

Domain层:

package com.hbsi.domain;

import java.util.Date;

 

public class LoadUser {
 
 private String id;
 //上传文件的名称,文件的uuid名
 private String savename; 
 //上传文件的真实名称
 private String realName;
 //记住文件的位置
 private String savepath;
 //文件的上传时间
 private Date uptime;    
 //文件的描述
 private String description;
 //上传人
 private String username;  

 public LoadUser() {
  super();
 }

 public LoadUser(String id, String savename, String realName,
   String savepath, Date uptime, String description, String username) {
  super();
  this.id = id;
  this.savename = savename;
  this.realName = realName;
  this.savepath = savepath;
  this.uptime = uptime;
  this.description = description;
  this.username = username;
 }

 public String getId() {
  return id;
 }

 public void setId(String id) {
  this.id = id;
 }

 public String getSavename() {
  return savename;
 }

 public void setSavename(String savename) {
  this.savename = savename;
 }

 public String getRealName() {
  return realName;
 }

 public void setRealName(String realName) {
  this.realName = realName;
 }

 public String getSavepath() {
  return savepath;
 }

 public void setSavepath(String savepath) {
  this.savepath = savepath;
 }

 public Date getUptime() {
  return uptime;
 }

 public void setUptime(Date uptime) {
  this.uptime = uptime;
 }

 public String getDescription() {
  return description;
 }

 public void setDescription(String description) {
  this.description = description;
 }

 public String getUsername() {
  return username;
 }

 public void setUsername(String username) {
  this.username = username;
 }

 @Override
 public String toString() {
  return "LoadUser [id=" + id + ", savename=" + savename + ", realName="
    + realName + ", savepath=" + savepath + ", uptime=" + uptime
    + ", description=" + description + ", username=" + username
    + "]";
 }
 
 
}

 

Dao层:

package com.hbsi.dao;

import java.sql.SQLException;
import java.util.Arrays;
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 com.hbsi.domain.User;
import com.hbsi.utils.DBManager_c3p0;

public class UserDaoImpl {
 
 //用户插入一条记录
 public void insert(){
  QueryRunner runner=new QueryRunner(DBManager_c3p0.getDataSource());
  String sql="insert into users(name,password) values('pp','1111')";
  try {
   runner.update(sql);
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
 
 private void update() throws SQLException {
  QueryRunner runner=new QueryRunner(DBManager_c3p0.getDataSource());
  String sql="update users set name=?,password=?,email=?,where id=?";
  Object[] param={"鸭蛋儿","222","
1137659183@qq.com",1};
  int i=runner.update(sql,param);
  if(i>0){
   System.out.println("修改成功");
   }
 }
 //删,改、查询
 public void find() throws Exception{
  QueryRunner runner=new QueryRunner(DBManager_c3p0.getDataSource());
  String sql="select * from users where is=?";
  User user=runner.query(sql,new BeanHandler(User.class),1);
  System.out.println(user.getId()+"  "+user.getName());
 }
 
 //批处理
 public void batch() throws SQLException{
  QueryRunner runner=new QueryRunner(DBManager_c3p0.getDataSource());
  String sql="insert into users(name,password) values (?,?)";
  Object[][] params={{"111","111"},{"222","222"},{"333","333"}};
  runner.batch(sql,params);
 }
 
 public void findall() throws SQLException{
  QueryRunner runner=new QueryRunner(DBManager_c3p0.getDataSource());
  String sql="select * from users";
  List<User> list=runner.query(sql,new BeanListHandler(User.class));
  System.out.println(Arrays.asList(list));
 }
 
 public static void main(String[] args){
  try {
   new UserDaoImpl().update();
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
}

 

Utils:

package com.hbsi.utils;


import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;


import com.mchange.v2.c3p0.ComboPooledDataSource;

public class DBManager_c3p0 {
 
 private static ComboPooledDataSource ds=null;
 
 static {
  ds=new ComboPooledDataSource("mysql");   
 }
 
 public static DataSource getDataSource(){
  return ds;
 }
 
 public static Connection getConnection() throws SQLException{
  return ds.getConnection();
 }
}

 

c3p0描述文件:

<c3p0-config>
 <default-config>
  <property name="driverClass">com.mysql.jdbc.Driver</property>
  <property name="jdbcUrl">jdbc:mysql://localhost:3306/jdbc</property>
  <property name="user">root</property>
  <property name="password">042181</property>
 
  <property name="automaticTestTable">con_test</property>
  <property name="checkoutTimeout">30000</property>
  <property name="idleConnectionTestPeriod">30</property>
  <property name="initialPoolSize">10</property>
  <property name="maxIdleTime">30</property>
  <property name="maxPoolSize">100</property>
  <property name="minPoolSize">10</property>
  <property name="maxStatements">200</property>  
 </default-config>
 
 <!-- This app is massive! -->
 <named-config name="mysql">
  <property name="driverClass">com.mysql.jdbc.Driver</property>
  <property name="jdbcUrl">jdbc:mysql://localhost:3306/jdbc</property>
  <property name="user">root</property>
  <property name="password">042181</property>
  
  <property name="acquireIncrement">50</property>
  <property name="initialPoolSize">100</property>
  <property name="minPoolSize">50</property>
  <property name="maxPoolSize">1000</property>
 </named-config>
 
</c3p0-config>

转载于:https://www.cnblogs.com/springside4/archive/2011/11/26/2481106.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值