Usually the easiest way is to do it in admin GUI at http://localhost:4848/ , choose Create New JDBC Connection Pools from the Common Tasks list on the front page right after login. You may need to scroll down a little bit to see it. On my screen, it is always hidden underneath the panel bottom. So for a while, I didn't notice its existence and always go to the left panel and choose
Resources | JDBC | Connection Pools, which does the same with more clicks. The rest steps are self-explanatory.
For repeated configuration tasks, I prefer using GlassFish command line tool asadmin (
$GLASSFISH_HOME/bin/asadmin). For example, this is script for creating mysql connection pool and datasource:
cp $HOME/mysql-connector-java-5.1.5-bin.jar $GLASSFISH_HOME/domains/domain1/lib/ext
$GLASSFISH_HOME/bin/asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlDataSource --property user=root:password=test:DatabaseName=test:ServerName=localhost:port=3306 test-pool
$GLASSFISH_HOME/bin/asadmin create-jdbc-resource --connectionpoolid test-pool jdbc/test
To create a connection pool that supports distributed transaction, use
com.mysql.jdbc.jdbc2.optional.MysqlXADataSourceas datasourceclassname, and set
asadmin ping-connection-pool test-poolto verify whether the created connection pool can connect to the database. The database server needs to be running.