问题描述
我正在尝试理解中的连接池,我正在使用 jsp,servlet和tomcat 6服务器我的应用程序。我在 java类dbconnection.java中编写了以下代码:
I am trying to understand connection pooling in java, i am using jsp, servlet and tomcat 6 server in my application. I have written the following code in a java class dbconnection.java:
我正在使用类型4 jdbc连接Windows Xp OS中的oracle 10g EE
I am using type 4 jdbc connection with oracle 10g EE in windows Xp OS
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class dbconnection { public Connection con = null; public Connection getConnection() throws Exception, SQLException { try { Class.forName("oracle.jdbc.driver.OracleDriver"); con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:abc","abc", "abc"); } catch(Exception e) { } return con; } public void removeConnection() throws SQLException { con.close(); } }
然后我正在重新连接servlet中的如下:
try{ dbconnection db= new dbconnection(); Connection con=db.getConnection(); } catch(Exception e){ } finally{ db.removeConnection();//removes connection }
是连接池还是<$ c中需要一些配置$ c> tomcat服务器还是别的什么?
推荐答案
你可以得到第三方库,或者您可以使用Java EE容器(例如,JBoss或WebSphere)为您提供的连接池。
You can get a third-party library, or you can use the connection pooling your Java EE container (for example, JBoss or WebSphere) provides for you.
为此,您需要配置和使用JNDI数据源。
To do this, you configure and use a JNDI datasource.
以下是Tomcat的详细信息:
Here are details for Tomcat:
http://www.tomcatexpert.com/blog/2012/01/24/using-tomcat-7-jdbc-connection-pool-production 一>
这篇关于如何在java中进行连接池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!