This page describes how to configure GlassFish for use with Jaybird. These instructions are based on GlassFish Server Open Source Edition 3.1.2.2 and Jaybird 2.2.3.

There are several ways to use Firebird from GlassFish:

This page currently only describe configuring as a datasource. Instructions for the JCA Connector will be added at a later time.

Adding driver JAR files to the domain

The first step in configuring GlassFish is placing the Jaybird files in the right location.

The files you need:

  • jaybird-2.2.3.jar (or jaybird-jdkxx-2.2.3.jar if you use Maven); WARNING do not use the jaybird-full jar file as it contains files which are provided by the application server itself and could lead to conflicts.
  • antlr-runtime-3.4.jar (optional, needed for retrieving generated keys)

You need to copy these jar files into domain-dir/lib and then restart GlassFish. domain-dir is the folder with your GlassFish domain (see also Making the JDBC Driver JAR Files Accessible in the GlassFish Server Administration Guide.

Configuring the datasource

  • Click ‘New’

New JDBC Connection Pool (Step 1 of 2)

  • Enter a poolname (eg FirebirdPool)
  • Select the resource type; all four options are supported by Jaybird, in general select javax.sql.DataSource (or javax.sql.XADataSource if you need distributed transactions). For the remainer we assume javax.sql.DataSource, but most of the configuration applies to all options.
  • For Database Driver Vendor enter Jaybird (or any text you want); note that Jaybird is not included in the dropdown list
  • Leave Introspect unchecked and click Next

New JDBC Connection Pool (Step 2 of 2)

  • Under Datasource Classname put org.firebirdsql.pool.FBSimpleDataSource (for Jaybird 2.3 and later: org.firebirdsql.ds.FBSimpleDataSource
    • For resource type javax.sql.XADataSource: org.firebirdsql.ds.FBXADataSource
    • For resource type javax.sql.ConnectionPoolDataSource: org.firebirdsql.ds.FBConnectionPoolDataSource
  • Enable ping (this helps identify potential configuration issues)
  • Enter a description (optional)
  • Configure the “Pool Settings” for your application needs (or leave as is)
  • Configure the “Transaction” settings for your application needs (by default Jaybird uses read-committed)

  • Set the additional properties (see also Properties below)
  • Save the settings. If you enabled ping the administration console will show that it was able to ping a connection

Creating the JDBC Resource

To be able to actually reference the connection pool in the previous step, we need to create a JDBC resource and link it to the connection pool. JDBC Resources are used to decouple applications from the actual connection pool you use.

  • Go to Resources > JDBC > JDBC Resources

  • Click New

  • Enter a JNDI name (eg “jdbc/FirebirdResource”)
  • Under Pool Name select the connection pool we just created (eg FirebirdPool)
  • Enter a description (optional)
  • Click OK to save the resource

Accessing the DataSource

To access the DataSource and getting a connection, you need to look up the JDBC resource using JNDI. For example:

InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("jdbc/FirebirdResource");
try (Connection con = ds.getConnection()) {
     // Do something with connection
}

Or with resource injection:

@Resource(name="jdbc/FirebirdResource")
private DataSource dataSource;

Properties

The additional properties of the datasource determines the configuration of the connection itself. GlassFish adds some properties mentioned in the JDBC specification by default, make sure to remove those you don’t use or need.

Unfortunately the available properties depend on which class you are using. We plan to remove these differences in Jaybird 2.3, favoring the more JDBC compliant options of the classes in org.firebirdsql.ds.

Properties for org.firebirdsql.pool.FBSimpleDataSource:

Property description example required?
database URL with hostname, port and database, essentially the same as the JDBC URL, but without the jdbc:firebirdsql: or jdbc:firebirdsql:embedded: or jdbc:firebirdsql:native: prefix //localhost:3050/c:/database/employee.fdb Yes
databaseName Alias for database (use only one) see database see database
userName The user for connecting sysdba Yes
user Alias for userName see userName see userName

Properties for org.firebirdsql.ds.FBXADataSource and org.firebirdsql.ds.FBConnectionPoolDataSource:

Property description example required?
databaseName Name of the database file or alias c:/database/employee.fdb Yes
database (deprecated!) This property is considered deprecated, use databaseName, serverName and portNumber properties instead //localhost:3050/c:/database/employee.fdb No
serverName Name of the Firebird server, default depends on the connection type (usually localhost) localhost No
portNumber Portnumber of the Firebird server, default is 3050 3050 No
user The user for connecting sysdba Yes
userName (deprecated!) This property is deprecated, use user property instead. see user No

Common properties:

Property description example required?
password The password of the user masterkey Yes
roleName User role to use for the connection managerrole No
charSet The java character set to use for connection UTF-8 No
encoding The Firebird character set to use for connection (usually only charSet or only encoding should be used, not both) UTF8 No
type The connection type, options are PURE_JAVA, NATIVE or EMBEDDED; PURE_JAVA being the default PURE_JAVA No

See Connection properties the release notes or the Jaybird manual for more properties

See also Administering Database Connectivity

 
config/glassfish.txt · Last modified: 2013/05/26 17:24 by mrotteveel