通过jsp+servlet+bean实现数据库查询

源代码在线查看: connpool.java

软件大小: 23 K
上传用户: liyuanhang
关键词: servlet bean jsp 数据库查询
下载地址: 免注册下载 普通下载 VIP

相关代码

				package shared;
				
				import java.sql.Connection;
				import java.sql.SQLException;
				
				import oracle.jdbc.pool.OracleConnectionCacheImpl;
				
				public class ConnPool
				{
					private OracleConnectionCacheImpl	oracleConnectionPool	= null;
					private String						Url						= null;
					private String						Name					= null;
					private String						Pwd						= null;
					private int							maxCount				= 0;
					
					public ConnPool(String Url, String Name, String Pwd, int maxCount)
					{
						try
						{
							this.Url = Url;
							this.Name = Name;
							this.Pwd = Pwd;
							this.maxCount = maxCount;
							oracleConnectionPool = new OracleConnectionCacheImpl();
							oracleConnectionPool.setURL(Url);
							oracleConnectionPool.setUser(Name);
							oracleConnectionPool.setPassword(Pwd);
							oracleConnectionPool.setMaxLimit(maxCount);
						}
						catch(SQLException sqlExp)
						{
							sqlExp.printStackTrace();
						}
						catch(NumberFormatException numFmtExp)
						{
							numFmtExp.printStackTrace();
						}
						catch(Exception ex)
						{
							ex.printStackTrace();
						}
					} 
					public Connection getConnection()
					{	
						Connection conn = null;
						try
						{
							if ( null != oracleConnectionPool)
							{
								synchronized(oracleConnectionPool)
								{
									conn = oracleConnectionPool.getConnection();
								}
							}
						}
						catch(Exception ex)
						{
							ex.printStackTrace();
						}
						
						return conn;
					}
				}			

相关资源