`

dbcp tomcat 配置方法 代码

阅读更多

由于需求在网上看了一些例子,就开始写二个代码学学dbcp  第一次做!!有很多不完美的地方,,但起码有效果了,,

 

做的视频也发上来了,也是第一次向往上发视频,,不要笑哦,做的很一般,,,很基本的一些东西,高手就别进来了!怕笑话!哈哈!!!

 

视频太大了上不了

 

 

分享到:
评论
1 楼 xiaoCong 2009-09-03  

做个实验。嘿嘿
package com.ascent.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.ascent.po.Authorization;
import com.ascent.po.Department;
import com.ascent.po.News;
import com.ascent.po.Userauth;
import com.ascent.po.Usr;
import com.opensymphony.xwork2.ActionContext;

public class AuthAction extends BaseAction {
	
	public String typ;
	public String pars;
	public String id;
	public String name;
	public String gid;
	public String sid;
	public String gname;
	public String sname;
	public String dept;
	
	public String getGname() {
		return gname;
	}
	public void setGname(String gname) {
		this.gname = gname;
	}
	public String getSname() {
		return sname;
	}
	public void setSname(String sname) {
		this.sname = sname;
	}
	public String getGid() {
		return gid;
	}
	public void setGid(String gid) {
		this.gid = gid;
	}
	public String getSid() {
		return sid;
	}
	public void setSid(String sid) {
		this.sid = sid;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPars() {
		return pars;
	}
	public void setPars(String pars) {
		this.pars = pars;
	}
	public String getTyp() {
		return typ;
	}
	public void setTyp(String typ) {
		this.typ = typ;
	}
	public String getDept() {
		return dept;
	}
	public void setDept(String dept) {
		this.dept = dept;
	}

	/**
	 * 查找用户权限
	 *
	 */
	public String auth(){
		String sql = "select a from Authorization a,Usr u,Userauth ua " +
				"where u.id=? and ua.userId=u.id and ua.authId=a.id";
		Map session = ActionContext.getContext().getSession();
		Usr user = (Usr) session.get("user");
		Integer[] value = new Integer[1];
		value[0] = user.getId();
		List list = newsService.selectSQL(sql,value);
		ActionContext.getContext().put("auth",list);
		return "qxx";
	}
	
	/**
	 * 查找应该显示在首页的头版头条和综合新闻
	 *
	 */
	public void index(){
		Map session = ActionContext.getContext().getSession();
		String sql = "from News n where (n.status=1 and n.type=1) or " +
				"(n.type=2 and n.checkstatus=2 and n.status=1) order by n.id" +
				" desc";
		List list = newsService.selectSQL(sql,null);
		if(list.size()>0){
			News news = (News) list.get(0);
			session.put("typ1",news);
		} else {
			session.put("typ1",null);
		}
		sql = "from News n where n.status=1 and n.type=2 and " +
				"n.checkstatus!=2 order by n.id desc";
		list = newsService.selectSQL(sql,null);
		List li = new ArrayList();
		if(list.size()>6){
			for(int i=0;i<6;i++){
				li.add(list.get(i));
			}
			session.put("typ2",li);
		} else {
			session.put("typ2",list);
		}
	}
	
	/**
	 *用户分配权限之前的寻找
	 */
	public String plot(){
		//部门集合
		String sql = "from Department";
		List list = newsService.selectSQL(sql, null);
		ActionContext.getContext().put("dept",list);
		
		//未分配权限的用户集合
		Department dt = (Department) list.get(0);
		sql = "from Usr u where u.deptid=? and u.id not in" +
				"(select ua.userId from Userauth ua,Authorization a where " +
				"ua.authId=a.id and a.columnId=?)";
		Integer[] value1 = {dt.getId(),Integer.parseInt(this.getTyp())};
		list = newsService.selectSQL(sql, value1);
		ActionContext.getContext().put("user1",list);
		
		//栏目管理的权限的用户集合
		sql = "select u from Usr u,Userauth ua,Authorization a where " +
				"u.id=ua.userId and u.deptid=? and a.columnId=? and " +
				"a.auth=1 and ua.authId=a.id";
		list = newsService.selectSQL(sql, value1);
		ActionContext.getContext().put("guser",list);
		
		//栏目审核的权限的用户集合
		sql = "select u from Usr u,Userauth ua,Authorization a where " +
				"u.id=ua.userId and u.deptid=? and a.columnId=? and " +
				"a.auth=2 and ua.authId=a.id";
		list = newsService.selectSQL(sql, value1);
		ActionContext.getContext().put("suser",list);
		return SUCCESS;
	}
	
	/**
	 * 根据部门查询用户
	 * @return
	 */
	public String deptUser(){
		String[] par = this.getPars().split(",");
		String sql = "from Usr u where u.deptid=? and u.id not in" +
						"(select ua.userId from Userauth ua,Authorization a " +
						"where ua.authId=a.id and a.columnId=?)";
		Integer[] value = {Integer.parseInt(par[0]),Integer.parseInt(par[1])};
		List list = newsService.selectSQL(sql, value);
		this.setId("");
		this.setName("");
		for(int i=0;i<list.size();i++){
			Usr user = (Usr) list.get(i);
			if(i==0){
				id = user.getId()+"";
				name = user.getNickname();
			} else {
				id = id+","+user.getId();
				name = name+","+user.getNickname();
			}
		}
		Integer[] va = {Integer.parseInt(par[0]),Integer.parseInt(par[1])};
		sql = "select u from Usr u,Userauth ua,Authorization a where " +
				"u.id=ua.userId and u.deptid=? and a.columnId=? and " +
				"a.auth=1 and ua.authId=a.id";
		list = newsService.selectSQL(sql, va);
		this.setGname("");
		this.setGid("");
		for(int i=0;i<list.size();i++){
			Usr user = (Usr) list.get(i);
			if(i==0){
				gid = user.getId()+"";
				gname = user.getNickname();
			} else {
				gid = gid+","+user.getId();
				gname = gname+","+user.getNickname();
			}
		}
		
		sql = "select u from Usr u,Userauth ua,Authorization a where " +
				"u.id=ua.userId and u.deptid=? and a.columnId=? and " +
				"a.auth=2 and ua.authId=a.id";
		list = newsService.selectSQL(sql, va);
		this.setSname("");
		this.setSid("");
		for(int i=0;i<list.size();i++){
			Usr user = (Usr) list.get(i);
			if(i==0){
				sid = user.getId()+"";
				sname = user.getNickname();
			} else {
				sid = sid+","+user.getId();
				sname = sname+","+user.getNickname();
			}
		}
		return "de";
	}
	
	public String addPlot(){
		String[] gid = this.getGid().split(",");
		String[] sid = this.getSid().split(",");
		String gsql = "from Authorization a where a.columnId=? and a.auth=1";
		String ssql = "from Authorization a where a.columnId=? and a.auth=2";
		Integer[] value = {Integer.parseInt(this.getTyp())};
		List glist = newsService.selectSQL(gsql,value);
		List slist = newsService.selectSQL(ssql,value);
		Authorization ga = (Authorization) glist.get(0);
		Authorization sa = (Authorization) slist.get(0);
		
		String sql = "select ua from Usr u,Userauth ua,Authorization a " +
				"where u.deptid=? and u.id=ua.userId and a.columnId=? " +
				"and a.auth=1 and a.id=ua.authId";
		Integer[] v = {Integer.parseInt(this.getDept()),
				Integer.parseInt(this.getTyp())};
		List list = newsService.selectSQL(sql, v);
		for(int i=0;i<list.size();i++){
			Userauth ua = (Userauth) list.get(i);
			newsService.deleteObject(ua);
		}
		sql = "select ua from Usr u,Userauth ua,Authorization a where " +
				"u.deptid=? and u.id=ua.userId and a.columnId=? and " +
				"a.auth=2 and a.id=ua.authId";
		list = newsService.selectSQL(sql, v);
		for(int i=0;i<list.size();i++){
			Userauth ua = (Userauth) list.get(i);
			newsService.deleteObject(ua);
		}
		for(int i=0;i<gid.length;i++){
			if(gid[0]!=null && !"".equals(gid[0])){
				Userauth ua = new Userauth();
				ua.setUserId(Integer.parseInt(gid[i]));
				ua.setAuthId(ga.getId());
				newsService.addObject(ua);
			}
		}
		for(int i=0;i<sid.length;i++){
			if(sid[0]!=null && !"".equals(sid[0])){
				Userauth ua = new Userauth();
				ua.setUserId(Integer.parseInt(sid[i]));
				ua.setAuthId(sa.getId());
				newsService.addObject(ua);
			}
		}
		return "am";
	}
}

相关推荐

    DBCP,C3P0,Tomcat_JDBC 性能及稳定性测试代码

    本项目提供了对三种常用的Java数据库连接池——DBCP(BasicDataSource)、C3P0和Tomcat JDBC的性能及稳定性测试代码。下面将详细介绍这三个连接池的工作原理、特性以及如何进行性能测试。 1. **DBCP ...

    Tomcat5.5 的dbcp配置

    本文将详细讲解如何在Tomcat 5.5中配置DBCP,以及JNDI(Java Naming and Directory Interface)的设置方法。 首先,了解DBCP的作用。数据库连接池允许应用复用已存在的数据库连接,而不是每次请求时都创建新的连接...

    JavaEE 使用Tomcat的自带DBCP管理数据源案例

    配置Tomcat的DBCP数据源通常涉及以下几个步骤: 1. **添加依赖**:确保你的项目已经包含DBCP的依赖库。在Maven项目中,可以在pom.xml文件中添加如下依赖: ```xml &lt;groupId&gt;commons-dbcp &lt;artifactId&gt;commons-...

    tomcat5.5 的dbcp配置

    通过以上三种方法,我们都可以成功配置Tomcat 5.5中的DBCP,实现数据库连接池的管理。不同之处在于配置文件的位置和方式。第一种方法适用于全局配置,第二种方法适合单个项目配置,并且更加灵活;第三种方法则更为...

    使用DBCP链接池详解附加代码例子

    本文将详细介绍DBCP连接池的配置和使用,并给出实际的代码示例。 4.1 连接池知识简介 数据库连接的建立和关闭是非常消耗资源的过程,因此引入了连接池的概念。连接池在系统启动时预创建一定数量的数据库连接,然后...

    COMMONS DBCP的使用与配置

    - **Spring**:在Spring框架中,可以将DBCP配置在XML配置文件中,或者使用Java配置类来声明数据源。 - **iBatis**:iBatis可以通过`SqlSessionFactoryBuilder`和`DataSource`接口结合DBCP来创建`SqlSessionFactory...

    tomcat_连接池数据库密码加密解密方法

    在Tomcat环境下,连接池通常使用Apache Commons DBCP(Database Connection Pool)来管理数据库连接。默认情况下,DBCP会直接读取配置文件中的用户名和密码,这意味着这些信息是以明文形式存在的。一旦服务器被非法...

    DBCP配置所需jar包(合)

    DBCP虽然简单易用,但在高并发场景下可能不如其他更现代的连接池如HikariCP和Tomcat JDBC Connection Pool。这些连接池提供了更好的性能和稳定性,例如更快的连接创建速度、更有效的连接管理策略等。 6. **注意...

    Tomcat 6.0配置数据源(DBCP)和JNDI使用

    总结,配置Tomcat 6.0的数据源(DBCP)和JNDI使用,主要是通过修改服务器和应用的配置文件,然后在代码中利用JNDI查找机制获取数据源,实现数据库连接的高效管理。通过实践和理解这些步骤,可以提升你的Java Web开发...

    TOMCAT中数据库连接池的几种配置方法_TOMCAT中数据库连接池的几种配置方法_

    以上是TOMCAT中常见的三种数据库连接池配置方法,包括Apache Commons DBCP、C3P0以及Tomcat内置的JDBC Pool。每种方式都有其特点和适用场景,开发者应根据实际需求选择合适的连接池组件,并进行相应的配置。正确配置...

    DBCP连接池原理分析

    Tomcat 7保留了DBCP连接池以确保向后兼容性,并引入了一个新的连接池——Tomcat JDBC pool作为DBCP的替代方案。尽管新推出的Tomcat JDBC pool被认为比DBCP 1.4更优秀,但由于不在本文讨论范围之内,故不作深入探讨。...

    利用dbcp实现数据库连接池

    5. **连接池的初始化**:在应用启动时,我们需要初始化DataSource,这通常在Web应用的上下文中完成,例如在Servlet容器(如Tomcat)中,可以在web.xml文件中配置ContextListener来初始化DataSource。 6. **获取和...

    SpringMVC+JNDI+Tomcat配置数据源

    ### SpringMVC+JNDI+Tomcat配置数据源 #### 一、简介 在Java Web开发中,数据源(DataSource)是管理数据库连接的重要组件。SpringMVC框架结合Java Naming and Directory Interface (JNDI) 和Apache Tomcat服务器...

    TOMCAT连接池DBCP,在server.xml中配置全局数据源详细的介绍,很有好用啊!!

    下面将详细介绍如何在TOMCAT中配置DBCP连接池,并在`server.xml`中设置全局数据源。 首先,确保你的开发环境中已经安装了TOMCAT服务器,并且你已经拥有一个适用于Java的数据库驱动,这里是MySQL的驱动程序`mysql-...

    commons中的DBCP连接池jar

    3. `commons-dbcp-1.4-sources.jar`:这个文件包含了DBCP 1.4的源代码,对于开发者来说,这是一个很好的学习和调试资源,可以查看源码了解内部实现细节。 4. `LICENSE.txt`、`RELEASE-NOTES.txt`、`README.txt`、`...

    tomcat5.0和tomcat5.5.12配置连接池的异同

    描述中提到"讲述tomcat5.0和tomcat5.5.12配置连接池(JNDI)的不同配置方法",意味着我们将探讨如何在每个版本的Tomcat中配置JNDI资源,以及这两个版本之间在配置过程中的具体变化。 **Tomcat连接池基础知识** 在...

    tomcat6.0中配置JNDI的DBCP连接

    在Java应用服务器中,如Tomcat 6.0,配置JNDI(Java Naming and Directory Interface)的DBCP(Database Connection Pool)连接池是管理数据库连接的重要步骤。JNDI是一个标准接口,允许应用程序查找和访问命名服务...

    dbcp连接池和配置文件

    3. 初始化连接池:在Java代码中读取配置,创建BasicDataSource实例,并设置配置信息。 4. 获取和归还连接:通过`BasicDataSource.getConnection()`获取连接,完成操作后调用`Connection.close()`,实际上连接并未...

    tomcat6配置数据库连接池代码

    在Tomcat6中配置DBCP连接池,需要先将DBCP的jar文件(例如:commons-dbcp.jar和commons-pool.jar)添加到Tomcat的`lib`目录下。在提供的压缩包中,可能有一个名为"所需的jar文件.txt"的文件,它应该列出了这些必要...

Global site tag (gtag.js) - Google Analytics