Set up a database connection pool in NetBeans

Source: Internet
Author: User
Tags auth commit sybase sybase database tomcat netbeans

In the past, it was necessary to set up a database connection pool with the help of third party software. But now NetBeans's Tomcat 5.5.7 and Sun application Server 8 can be set directly. Let's talk about how to set up under Tomcat 5.5.7.

1. Download the private connection driver for the database and copy it to the C:\Program Files\netbeans-4.1\enterprise1\jakarta-tomcat-5.5.7\common\lib folder below.

Suppose the database used is Sybase's adaptive Server Anywhere, download jconnect-6_0 from the Sybase official site, extract jconn3 from the drive, and copy it to the folder above.

2. Start Tomcat, enter http://localhost:8084/admin/in IE, log in as admin. User Login method can refer to the 5th floor. Click on the data Sources in resources, select Create New data source in the dropdown box on the right data source, and follow the example below to fill in the following table:

JNDI Name: sybase/poolDB  /* 根据喜好填 */
Data Source URL: jdbc:sybase:Tds:<localhost>:<端口号>
/* 数据库的地址,此为jconn3的形式,端口号需查询确认,但一般都是固定的,除非自己更改 */
JDBC Driver Class: com.sybase.jdbc3.jdbc.SybDriver  /* jconn3的驱动 */
User Name: dba            /* 用户名,默认为dba */
Password: ***             /* 密码,默认为sql */
Max. Active Connections: 4      /* 最大活动连接数 */
Max. Ide Connections: 2        /* 最大空闲连接数 */
Max. Wait for Connecton: 5000     /* 等待连接的最大秒数 */
Validation Query:           /* 验证字符串,可不填 */

By pressing "save" and then pressing "Commit Changes", Tomcat saves the change in the background to the Server.xml file. "Commit Changes" is the easiest to forget, be careful.

3. All of the following are transferred to the NetBeans environment settings. Content modified in Context.xml:

<Context path="/Matrix">
 <ResourceLink global="sybase/poolDB" name="sybase/poolDB" type="javax.sql.DataSource"/>
</Context>

"/matrix" is the root address of this Web application, expressed as Http://localhost:8084/Matrix.

4. By adding in Web.xml:

<resource-ref>
<description>Sybase Database Connection Pool</description>
<res-ref-name>sybase/poolDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

5. OK, you can use the connection pool. The following code is an example of using the JSTL tag library in a JSP file.

<sql:query var="queryresults" dataSource="sybase/poolDB">
SELECT * FROM customer
</sql:query>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.