JDBC 4.0 support in GlassFish-V2



GlassFish V2 supports JDBC 4.0 applications in jdk 1.6
Users can configure jdbc 4.0 capable datasource by specifying the vendor classname while creating jdbc connection pool.
Following sample will illustrate how to create a jdbc 40 capable datasource using JavaDB (aka Derby).

GlassFish v2 bundles JavaDB which supports jdbc 4.0 also.
JDBC 4.0 datasource implementation classes provided by Derby are :

org.apache.derby.jdbc.ClientConnectionPoolDataSource40
org.apache.derby.jdbc.ClientDataSource40
org.apache.derby.jdbc.ClientXADataSource40


To create a jdbc-connection-pool in GlassFish, templates are provided for various databases
in GF_INSTALL_DIR/lib/install/templates/resources/jdbc

"javadb_type4_datasource.xml" is for jdbc-3.0 datasource.

eg:
Copy the file and modify the "datasource-classname" to "org.apache.derby.jdbc.ClientDataSource40"
and "res-type" to "javax.sql.DataSource"
Specify appropriate values to connection parameters eg (user, password, hostname, databasename etc.,)
and name of jdbc connection pool and jdbc resource.

<resources>
    <jdbc-connection-pool
        name="jdbc-40-pool"
        datasource-classname="org.apache.derby.jdbc.ClientDataSource40"
        res-type="javax.sql.DataSource">
        <property name="user" value="userid"/>
        <property name="password" value="secret"/>
        <property name="databaseName" value="testdb"/>
        <property name="serverName" value="localhost"/>
        <property name="portNumber" value="1527"/>
        <property name="connectionAttributes" value=";create=true"/>
    </jdbc-connection-pool>

    <jdbc-resource
        enabled="true"
        jndi-name="jdbc/jdbc-40-resource"
        object-type="user"
        pool-name="jdbc-40-pool"/>
</resources>

Create jdbc connection pool & resource as :

GF_INSTALL_DIR/bin/asadmin add-resources GF_INSTALL_DIR/lib/install/templates/resources/jdbc/javadb_jdbc40_datasource.xml
 =========================
Added Resource Type: jdbc-connection-pool
 =========================
Added Resource Type: jdbc-resource
Command add-resources executed successfully.

FAQ:

1) GlassFish is already installed using jdk 1.5. Can its run-time be jdk 1.6 ?
Yes. change the AS_JAVA entry in GF_INSTALL_DIR/config/asenv.conf to use jdk 1.6 and restart app.server

2) GlassFish is installed using jdk 1.6. Is it possible to use jdbc 3.0 datatsources ?
Yes, no changes are required.

Bundles Used :

  • JavaDB (Derby 10.2.2.0) bundled with GlassFish


Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

jagadish

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today