package com.jspdev.util;

import java.sql.*;
import javax.naming.*;
import javax.sql.DataSource;
//一个用于查找数据源的工具类。
public class DatabaseConn {
	public  static  synchronized Connection getConnection() throws Exception
	{
		try
		{
			
			Context initCtx = new javax.naming.InitialContext(); 
            Context envCtx = (Context) initCtx.lookup("java:comp/env"); 
            DataSource ds = (DataSource)envCtx.lookup("jdbc/bn"); ;
			return ds.getConnection();
		}
		catch(SQLException e)
		{
			throw e;
		}
		catch(NamingException e)
		{
	     	throw e;
		}
		
	}

}