1

I am trying to migrate an application from Glassfish 3.1.1.2 to Glassfish 4.0. During this process I came up with a problem accessing our database.

It looked like when injecting a jdbc resouce

@Resource(name = "jdbc/MyDBResource") 
private DataSource datasource;

Glassfish (or Java) gave me a DataSource pointing to the Derby JDBC pool (which is marked as the default jdbc pool). I found out for this to work on Glassfish 4 I needed to include a glassfish-resource.xml file containing the jdbc pool and jdbc resource definitions. I created the file and added it in one of the project modules:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
        <jdbc-connection-pool 
         name="MyDBConnectionPool" 
         res-type="javax.sql.DataSource"
         datasource-classname="com.bla.bla.XYZDataSource"
         pool-resize-quantity="3" 
         max-pool-size="200" 
         steady-pool-size="0"
         statement-timeout-in-seconds="20" >
       <property name="serverName" value="db.url.com" />
       <property name="user" value="scottTheTiger" />
       <property name="password" value="theMightyPassword" />
     </jdbc-connection-pool>

    <jdbc-resource jndi-name="java:module/jdbc/MyDBResource" 
     pool-name="MyDBConnectionPool"/>
</resources>

I also changed my code to point to the new resource

@Resource(name = "java:module/jdbc/MyDBResource") 
private DataSource datasource;

It works fine.

In the present installation (Glassfish 3.1.1.2) the connection pool was defined using the admin console. We sometimes need to tweek the connection pool settings (size, time to live etc) and maybe flush the pool.

I noticed that when I deploy the application, the jdbc pool and resource that I added via the xml file do not show up in the admin console nor does the asadmin list-reource-refs command include them in the results. So if we need to change something in the pool, is there any way to do it without redeploying the whole application?

  • [The documentation, Part II, chapter 12 Administering Database Connectivity](https://glassfish.java.net/docs/4.0/administration-guide.pdf) tells to use `list-jdbc-resources` subcommand in the remote admin console to list JDBC resources. Second the same documentation states that changes in the JDBC pool configuration doesn't need restarts. – zloster Apr 06 '17 at 17:24
  • `Dynamic Configuration Changes With dynamic configuration, changes take effect while the DAS or instance is running. The following configuration changes do not require restart: ■ Adding or removing JDBC, JMS, and connector resources and pools (Exception: Some connection pool properties affect applications.)` – zloster Apr 06 '17 at 17:25
  • Unfortunately the jdbc-connection-pools defined in the glassfish-resources.xml file I mentioned, do not show up in the results of list-jdbc-resources. I am looking for a way to access and update them while the server is up and running. – user1533878 Apr 07 '17 at 15:05
  • Please take a more careful look at the documentation: there are `asadmin> list-jdbc-connection-pools` and `asadmin> list-jdbc-resources` commands. – zloster Apr 08 '17 at 16:42

0 Answers0