Topic: oracle 9i 如何在tomcat中配置连接池? |
Print this page |
1.oracle 9i 如何在tomcat中配置连接池? | Copy to clipboard |
Posted by: mazalet Posted on: 2003-08-13 13:58 小弟的项目中需要配置连接池,但不知道如何入手, 请教大家给各例子或参考指南! |
2.Re:oracle 9i 如何在tomcat中配置连接池? [Re: mazalet] | Copy to clipboard |
Posted by: dissip Posted on: 2003-08-13 16:04 refer to http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html |
3.Re:oracle 9i 如何在tomcat中配置连接池2? [Re: mazalet] | Copy to clipboard |
Posted by: dissip Posted on: 2003-08-13 16:06 maybe you also need http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-resources-howto.html |
4.Re:oracle 9i 如何在tomcat中配置连接池? [Re: mazalet] | Copy to clipboard |
Posted by: 256456 Posted on: 2003-08-13 20:35 在 server.xml 中加入如下配置: <DefaultContext debug="0" privileged="true" reloadable="true" useNaming="true" crossContext="true"> <Resource name="jdbc/DefaultDS" auth="SERVLET" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/DefaultDS"> <parameter><name>username</name><value>tw</value></parameter> <parameter><name>password</name><value>99999999</value></parameter> <parameter><name>driverClassName</name> <value>oracle.jdbc.driver.OracleDriver</value></parameter> <parameter><name>url</name> <value>jdbc:oracle:thin:@172.16.9.95:1521:hbbgt</value></parameter> </ResourceParams> </DefaultContext> |
5.更灵活的方法//Re:oracle 9i 如何在tomcat中配置连接池? [Re: mazalet] | Copy to clipboard |
Posted by: felexs Posted on: 2003-08-14 08:59 1. 使用TOMCAT的server.xml及DBCP使用连接池,通用的模式,但没有利用Oracle本身提供的连接池,同时多个application使用同样的配置,不一定能够满足需求。 2. 使用自定义的数据源绑定,充分利用数据库厂商提供的连接池、cache。 3. 具体思路提示: a. 一个DataSourceListener上下文环境侦听器,在服务器启动时绑定实际的数据源; b. 抽象配置类DataSourceConfig,各个数据库连接池从此扩充; c. OracleConfig,包装Oracle自己的连接池 oracle.jdbc.pool.OracleConnectionCacheImlp |
6.Re:更灵活的方法//Re:oracle 9i 如何在tomcat中配置连接池? [Re: felexs] | Copy to clipboard |
Posted by: mazalet Posted on: 2003-08-14 10:12 felexs wrote: 能不能介绍的详细一点或者告诉我可以参考的文章或连接、例子什么的。 |
7.Re:oracle 9i 如何在tomcat中配置连接池? [Re: mazalet] | Copy to clipboard |
Posted by: felexs Posted on: 2003-08-14 13:38 思路参考了wrox 的《Professional Java Servlets 2.3 》 中文版为:《Java servlet 2.3编程指南》 我没法在这个贴子里加附件,代码: package persistence; import java.io.InputStream; import javax.servlet.ServletContext; import javax.xml.parsers.*; import org.xml.sax.InputSource; import org.w3c.dom.*; public abstract class Config { protected Element root; protected void init(ServletContext sctx, String xmlFile) throws Exception { InputStream is = null; // Obtain the root element. try { is = sctx.getResourceAsStream(xmlFile); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(new InputSource(is)); root = doc.getDocumentElement(); } finally { if (is != null) { is.close(); } } } protected void cleanup() { root = null; } protected String getElementText(Element parent, String name) { NodeList nodeList = parent.getElementsByTagName(name); if (nodeList.getLength() == 0) { return null; } Element element = (Element) nodeList.item(0); StringBuffer sb = new StringBuffer(); for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) { if (child.getNodeType() == Node.TEXT_NODE) { sb.append(child.getNodeValue()); } } return sb.toString().trim(); } } package persistence.database; import persistence.Config; import javax.servlet.ServletContext; import javax.sql.DataSource; public abstract class DataSourceConfig extends Config { private static final String DATABASE_USER = "DatabaseUser"; private static final String DATABASE_PASSWORD = "DatabasePassword"; private static final String SERVER_NAME = "ServerName"; private static final String DATABASE_NAME = "DatabaseName"; private static final String SERVER_PORT = "ServerPort"; protected DataSource ds; protected String databaseUser; protected String databasePassword; protected String serverName; protected String portNumber; protected String databaseName; public void init(ServletContext sctx, String xmlFile) throws Exception { super.init(sctx, xmlFile); // Read URI properties. databaseUser = getElementText(root, DATABASE_USER); databasePassword = getElementText(root, DATABASE_PASSWORD); databaseName = getElementText(root, DATABASE_NAME); serverName = getElementText(root, SERVER_NAME); portNumber = getElementText(root, SERVER_PORT); } public DataSource getDataSource() { return ds; } } package persistence.database.oracle; import persistence.database.DataSourceConfig; import javax.servlet.ServletContext; //import javax.sql.DataSource; import oracle.jdbc.pool.OracleConnectionCacheImpl; public class OracleConfig extends DataSourceConfig { private static final String MAX_CONNECTIONS = "MaxConnections"; public void init(ServletContext ctx, String xmlFile) throws Exception { super.init(ctx, xmlFile); String databaseURL = "jdbc:oracle:thin@" + serverName + ":" + portNumber + ":" + databaseName; ds = new OracleConnectionCacheImpl(); ((OracleConnectionCacheImpl)ds).setURL(databaseURL); ((OracleConnectionCacheImpl)ds).setUser(databaseUser); ((OracleConnectionCacheImpl)ds).setPassword(databasePassword); try{ int maxConnections = Integer.parseInt( getElementText(root, MAX_CONNECTIONS)); ((OracleConnectionCacheImpl)ds).setMaxStatements(maxConnections); } catch(NumberFormatException n) { // } cleanup(); } } datasource-config.xml: <?xml version="1.0" encoding="ISO-8859-1"?> <DataSource> <DatabaseUser>sms</DatabaseUser> <DatabasePassword>sms</DatabasePassword> <DatabaseName>ittest</DatabaseName> <ServerName>10.38.8.20</ServerName> <ServerPort>1521</ServerPort> <MaxConnections>10</MaxConnections> </DataSource> |
8.Re:oracle 9i 如何在tomcat中配置连接池? [Re: mazalet] | Copy to clipboard |
Posted by: felexs Posted on: 2003-08-29 09:44 我回了这么实用的代码,版主给我加分吧! |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |