c3p0使用

c3p0-config.xml 文件  放在在src下


	
		com.mysql.jdbc.Driver
		jdbc:mysql://localhost:3306/test
		root
		123456
		2
		5
		1
		5
	



dbutil.java 源代码

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class dbutil {
  private static  ComboPooledDataSource  dataSource=new ComboPooledDataSource();

public static ComboPooledDataSource getDataSource() {
	return dataSource;
}

public static void setDataSource(ComboPooledDataSource dataSource) {
	dbutil.dataSource = dataSource;
}
    
    
}


dao程序需要第三方 commons-dbutils-1.4.jar jar包

import org.apache.commons.dbutils.QueryRunner;

public class EmpsDao {
	 
  public void add(Emps emp) throws Exception{
	  QueryRunner runner=new QueryRunner(dbutil.getDataSource());
	  String sql="insert into emps(id,username,salary) values(?,?,?)";
	  Object[] param={emp.getId(),emp.getUsername(),emp.getSalary()};
	  runner.update(sql, param);
	  
	  //dbutil.getDataSource().getConnection();
  }
  
  public static void main(String[] args) {
	Emps emp=new Emps("zhangsan",400.34);
	EmpsDao e=new EmpsDao();
	try {
		e.add(emp);
	} catch (Exception e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	
}
}



你可能感兴趣的:(ssh)