1.连接池
a.点击项目名称,右键选择New(新建)->other...
b.在categories选框里选择:Glassfish 右边File types(文件类型)选择:JDBC Connection Pool
c.JDBC Connection Pool Name(JDBC连接池名称):输入BlogPool;连接之前创建的blogs库。
d.全部默认选项,按finish(完成),连接池算是创建完成了。
2. 数据源
按步骤1-a,1-b选择JDBC Resource
c.Gerneral Attributes(一般属性)Connection Pool选择Use Existing JDBC Connetion Pool(使用已有的连接池)
下拉单里选择刚刚创建的BlogPool,JNDI Name里填写:jdbc/Blog
Finish以后,在项目的Server Resources的sun-resources.xml文件里可以查看到连接池和数据源的信息。
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Resource Definitions //EN" "http://www.sun.com/software/appserver/dtds/sun-resources_1_3.dtd">
3 <resources>
4 <jdbc-resource enabled="true" jndi-name="jdbc/Blog" object-type="user" pool-name="BlogPool">
5 <description/>
6 </jdbc-resource>
7 <jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="BlogPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
8 <property name="URL" value="jdbc:mysql://localhost:3306/blogs"/>
9 <property name="User" value="root"/>
10 <property name="Password" value="()"/>
11 </jdbc-connection-pool>
12 </resources>
13