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

📄 dbutil.java

📁 一个管理系统 用java作的
💻 JAVA
字号:
/*
 *  僔僗僥儉丂丂丗 嶳廏HR僔僗僥儉奐敪
 *  僒僽僔僗僥儉丗 WEB僔僗僥儉
 *
 *   VER    丂曄峏擔     丂晹壽      扴摉幰  丂曄峏撪梕
 *  -----------------------------------------------------------------
 *  V1.00 丂丂${date} (ShanXiu丂Soft)  Tuwenjie   弶斉
 *
 *       (C) Copyright SHANXIU CORPORATION 2006
 *                     All Rights Reserved.
 *
 */


package net.shanxiu.HR.dao;

/**
 * DbUtil
 */

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.naming.InitialContext;
import javax.sql.DataSource;

import net.shanxiu.HR.entity.CommonLog;
import net.shanxiu.HR.entity.HrException;


/**
 * <strong>DbUtil</strong> is a utility class to create
 * a connection to database.
 */
/******************************************************************************
 * 僋儔僗偺奣梫丗update class and search class's father include connection and 
 *               release resources         
 * 
 * @author  嶌惉幰 tuwenjie
 * @version 1.0
*******************************************************************************
 */
public class DbUtil {
	
    protected DataSource dataSource = null;
    
    protected Connection connection = null;
    
    protected Statement stm         = null;
    
	protected ResultSet rs          = null; 

public DbUtil() {

}

/*******************************************************************************
 * 張棟撪梕偺奣梫:connect to database
 * 
 * @param   堷悢:null
 * @return  栠傝抣:connection 
 * @exception  ?忢丗Exception
 *******************************************************************************
 */
protected java.sql.Connection connectToDb() throws HrException{
	
    try {
		InitialContext ctx = new InitialContext();
		
		String jndiName    = "java:comp/env/jdbc/test";
		
		dataSource = (DataSource)ctx.lookup(jndiName);
		
		connection = dataSource.getConnection();
		
			
    	 }catch (Exception ex){
    	     
    	     CommonLog.getInstance().logMgError(ex.toString(),ex);
    	     throw (new HrException());
    	 }
    return connection;
    	 
}

        //release resultset
protected void silentClose(ResultSet rs) { 
    
	if (null != rs) {
		try {
			rs.close();
		} catch (SQLException e) {
			//do nothing
		}
	}
}

        //release statement
protected void silentClose(Statement stm) { 
    
    if (null != stm) {
        try {
            stm.close();
        } catch (SQLException e) {
            //do nothing
        }
    }
}

        //release connection
protected void silentClose(Connection con) { 
    
    if (null != con) {
        try {
            con.close();
        } catch (SQLException e) {
            //do nothing
        }
    }
}
	
}
		
		
		
		
		
		
		

⌨️ 快捷键说明

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