翻译原文——精选推荐

更新时间:2023-05-13 23:50:39 阅读: 评论:0

翻译原文
In the $CATALINA_HOME/l configuration file, within the scope of the localhost <Host> component, add the following <DefaultContext> element:
<DefaultContext>
<Resource name=‖jdbc/WroxTC5‖ auth=‖Container‖
type=‖javax.sql.DataSource‖/>
<ResourceParams name=‖jdbc/WroxTC5‖>
<parameter>
<name>driverClassName</name>
<value&sql.jdbc.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost/wroxtomcat</value>
</parameter>
<parameter>
<name>urname</name>
<value>empro</value>
西藏旅游最佳时间</parameter>
<parameter>
<name>password</name>
<value>empass</value></parameter>
<parameter>
每日免费一签
<name>maxActive</name>
<value>20</value></parameter>
<parameter>
<name>maxIdle</name>
<value>30000</value></parameter>
<parameter>
<name>maxWait</name>
<value>100</value>
</parameter>
</ResourceParams>
</DefaultContext>
The urlparameter is often named driverNamein old documentation for legacy reasons (older version name), and can still be specified using the old name. For all new work, u url.
This configuration will work fine with Tomcat 5 or 4, as they both u DBCP connection pooling.
承君之欢Two optional parameters (removeAbandoned and removeAbandonedTimout) help with the recycling of databa connections, even for tho that may not be relead properly becau of faulty developer coding.
When the number of available connections in the pool runs low, the DBCP pool management code will recycle connections bad on an elapd idle timeout. For example, the following additional parameters
will cau the DBCP pool management code to recycle all JDBC connections that are idled for more than 15 minutes:
<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>
<parameter>
<name>removeAbandonedTimeout</name>
<value>15</value>
</parameter>
If you are running an older Tomcat relea that us the Tyrex (licend) data-source factory by default (Tomcat 4.0.4 or later up to 4.1.3), you will need to add the following parameter to the <ResourceParams> element:
<ResourceParams name=‖jdbc/WroxTC5‖>
<parameter>
<name>factory</name>
<value>s.dbcp.BasicDataSourceFactory</value>
</parameter>
...
In addition, becau Tomcat 5 includes the required Jakarta Commons libraries by default, you will find the DBCP and dependent libraries in the
$CATALINA_HOME/common/lib directory. The binaries include the following:
❑ commons-dbcp-1.1.jar
❑ commons-collection.jar
❑ commons-pool-1.1.jar
Tomcat 4 also already us the DBCP library code by default since the relea of Tomcat 4.1.3. If you are using versions prior to 4.1.3, you will need to download the aforementioned JAR files from the Jakarta
Commons site at the following URL and copy them into the directory manually: /commons/index.html
Step 2—Add the <resource-ref/> entries l
Instead of creating a new Web application, an easy way to add a test JSP is by adding it to an existing example application from Tomcat. To do this, change directory to $CATALINA_HOME/webapps/jsp-examples/WEB-INF and edit l file (this is the deployment descriptor of the jsp-examples Web application). Add the following highlighted code l (note that it should be added immediately after the last
<env-entry> element in the file):
...
<env-entry>
<env-entry-name>foo/name4</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>10</env-entry-value>
品质检验</env-entry>
<resource-ref>
<res-ref-name>jdbc/WroxTC5</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
This <resource-ref> entry makes the jdbc/WroxTC5 context, via JNDI APIs, available within the jsp-examples Web application.
Step 3—U JNDI to look up a data source
Finally, it is time to write the code that will look up the data source and start querying the databa. The following
出生英文JSP, JDBCTest.jsp, will do exactly this. Put it into a
$CATALINA_HOME/webapps/jsp-examples/
wroxjdbc directory (create this directory yourlf). Pay special attention to the way JNDI is ud to obtain the data source (code highlighted).
<html>
<head>
<%@ page errorPage=‖errorpg.jsp‖
import=‖java.sql.*,
javax.sql.*,
ps图片变形
java.io.*,
javax.naming.InitialContext,
javax.naming.Context‖ %>
</head>
<body>
<h1>JDBC JNDI Resource Test</h1>
<%
InitialContext initCtx = new InitialContext();
DataSource ds = (DataSource)
initCtx.lookup(―java:comp/env/jdbc/WroxTC5‖);
Connection conn = ds.getConnection();
植物节Statement stmt = ateStatement();
ResultSet rt = uteQuery(―lect * from employee;‖);
%>
<table width=’600’ border=’1’>
<tr>
<th align=’left’>Employee ID</th>
<th align=’left’>Name</th>
<th align=’left’>Department</th>
</tr>
<%
while (rt.next()) {
%>
<tr><td><%= rt.getString(1) %></td>
<td><%= rt.getString(2) %></td>
<td><%= rt.getString(4) %></td>
</tr>
波斯帝国
<% }
rt.clo();
stmt.clo();
conn.clo();
initCtx.clo();
%>
</table>
</body>
</html>
The JNDI code highlighted here first obtains the InitialContext from Tomcat. It then us this context to look up the JNDI resource that we have configured. Note that a ll Tomcat JNDI resources are found relative to java:comp/env/. Once the data source is

本文发布于:2023-05-13 23:50:39,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/894771.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:西藏   翻译   检验   图片
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图