Creating DataSource in Glassfish3 for Sybase 7 Adaptive Server and JPA2

Couple of days back I came across a scenario where I had to configure Sybase Adaptive Server Anywhere 7 database to be used with JPA 2.
The Challenging parts were creating the datasource and pool in Glassfish 3 and make it work.In this post i'll describe how to create a datasource in glassfish 3 for age old legacy Sybase 7 

Find Required Libraries:

Sybase 7 comes with jconn2.jar (as I can remember …. but this doesn't matter.) Yes , It is possible to create a datasource with jconn2.jar also but it will not work with JPA 2 because for  jdbc3 is required for JPA 2.

So in-order make a datasource that works perfectly with JPA it is needed to find jconn3.jar .

Create Connection Pool

In Glassfish3 a connection pool is needed. So I first created the connection pool.

Create Datasource

Then datasource was created using the above pool.

Steps To Create DataSource

  • Copy the jconn3.jar to lib folder of your glassfish3 domain. If your domain is domain1 then lib folder will be in C:\Program Files\glassfish-3.1.2.2\glassfish\domains\domain1\lib\ 
    (C:\Program Files\ is where glassfish3 is installed in machine.
  • Login to Glassfish3 as admin console.
    (Pointing your browser to localhost:4848 will get you there .You may replace localhost with the ip according to the ip of you Glassfish3 host.)

Fig 1 : Glassfish Admin Console

  • Go to Resources > JDBC >JDBC Connection Pools from the left pane of glassfish3 admin console.
Fig 2 : GlassFish JDBC Connection Pools
  • Then click new and start creating the new connection pool.
GlassFish JDBC Connection Pool For Sybase(General Settings)
Fig 3 : GlassFish JDBC Connection Pool For Sybase(General Settings) 

  • Give pool a name. Remember Pool Name is mandatory.
  • Select resource type as javax.sql.DataSource
  • Database Driver Vendor as Sybase.
  • Enable introspect
  • Click next on top pf the right hand side 
GlassFish JDBC Connection Pool For Sybase(General Settings)
Fig 4 : GlassFish JDBC Connection Pool For Sybase(General Settings)

  • DataSource Class Name should be selected as above (com.sybase.jdbc3.jdbc.SybDataSource)
  • Enable Ping.
  • Then in the below property settings fill at least followings as shown in the below image.

GlassFish JDBC Connection Pool For Sybase(Additional Properties)
Fig 5 : GlassFish JDBC Connection Pool For Sybase(Additional Properties)


  • Network Protocol should be Tds
  • PortNumber should be the port which sybase server runs
  • serverName have to be name or ip of the host machine
  • user name and password are valid user names and passwords for login to sybase.
  • Then save and press ping button to ping .You may get screen similar to below if everything has gone well ..

GlassFish JDBC Connection Pool For Sybase(Ping Succeeded)
Fig 6 : GlassFish JDBC Connection Pool For Sybase(Ping Succeeded)


  • Then make a datasource using the created pool. Go to Resources > JDBC >JDBC Resources

    GlassFish JDBC Resource (Create New)
    Fig 7 : GlassFish JDBC Resource (Create New )
  • Click New Give a JNDI Name and select the pool created as the Pool Name
Fig 8 : GlassFish DataSource using sybase pool 
  • Now Data-source creation is finished and this will work with JPA 2 also.

Comments

Popular Posts