⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 strutsdatasource.java

📁 基于JAVA的一个注册系统 最初只是为了公司做演示使用
💻 JAVA
字号:
package net.yefei.cmn.db;
import java.sql.*;
import javax.sql.*;
import java.io.*;
/*
* @author ye fei
* @version 1.00, 2003/04/15
* @copyright www.studyjava.com
*/
import org.apache.struts.util.*;

public class StrutsDataSource implements DbDataSource {
	private GenericDataSource sds;
	public void init(DataSourceBean b) throws Exception{
		sds = new GenericDataSource();

		//sds.addProperty("autoCommit",b.getAutoCommit());
		if(b.getAutoCommit().equals("true"))
			sds.setAutoCommit(true);
		else
			sds.setAutoCommit(false);

		//sds.addProperty("description",b.getName());
		sds.setDescription(b.getName());

		//sds.addProperty("driverClass",b.getDriverClass());
		sds.setDriverClass(b.getDriverClass());

		//sds.addProperty("maxCount",b.getMaxCount());
		sds.setMaxCount(Integer.parseInt(b.getMaxCount()));

		//sds.addProperty("minCount",b.getMinCount());
		sds.setMinCount(Integer.parseInt(b.getMinCount()));

		//sds.addProperty("password",b.getDbPassword());
	 	sds.setPassword(b.getDbPassword());

		//sds.addProperty("pingCommand",b.getPingCommand());
		String pingC = b.getPingCommand();
		if(pingC != null && !pingC.equals(""))
			sds.setPingCommand(pingC);

		//sds.addProperty("pingQuery",b.getPingQuery());
		String pingQ = b.getPingQuery();
		if(pingQ != null && !pingQ.equals(""))
 			sds.setPingQuery(pingQ);

		//sds.addProperty("url",b.getDbUrl());
 		sds.setUrl(b.getDbUrl());

		//sds.addProperty("user",b.getDbUser());
 		sds.setUser(b.getDbUser());

		//sds.addProperty("readOnly",b.getReadOnly());
		if(b.getReadOnly().equals("true"))
			sds.setReadOnly(true);
		else
			sds.setReadOnly(false);

		if(b.getLoginTimeout() != null){
			try{
				int t = Integer.parseInt(b.getLoginTimeout());
				setLoginTimeout(t);
			}catch(Exception e){
			}
		}

		if(b.getDebug() != null){
			try{
				int t = Integer.parseInt(b.getDebug());
				sds.setDebug(t);
				sds.setLogWriter(new PrintWriter(System.out, true));
			}catch(Exception e){
			}
		}

		sds.open();


	}
	public void destroy(){
		try{
			sds.close();
		}catch(Exception e){
		}
		sds = null;
	}
	public int getMaxCount(){
		return sds.getMaxCount();
	}
	public int getMinCount(){
		return sds.getMinCount();
	}
	public boolean getAutoCommit(){
		return sds.getAutoCommit();
	}
	public int getCashedConnetionCount(){
		return sds.getActiveCount();
	}
	public Connection getConnection() throws SQLException{
		synchronized(sds){
			if(sds.getUseCount() >= getMaxCount())
				throw new NoConnectionException(sds.getDescription(), getMaxCount());
		}
		return sds.getConnection();
	}
	public Connection getConnection(String username, String password) throws SQLException{
		return sds.getConnection(username,password);
	}
 	public int getLoginTimeout() throws SQLException {
		return sds.getLoginTimeout();
 	}
	public  PrintWriter getLogWriter() throws SQLException {
		return sds.getLogWriter();
	}
 	public void setLoginTimeout(int seconds) throws SQLException {
		sds.setLoginTimeout(seconds);
	}
 	public void setLogWriter(PrintWriter out) throws SQLException {
		sds.setLogWriter(out);
 	}
 	public String getUrl() {
		return sds.getUrl();
 	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -