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文件里可以查看到連接池和數據源的信息。
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
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