File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Java Products and Servers and the fly likes Connectin pool in GlassFish Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Java Products and Servers
Bookmark "Connectin pool in GlassFish" Watch "Connectin pool in GlassFish" New topic

Connectin pool in GlassFish

K Kiran Kumar
Ranch Hand

Joined: Jan 04, 2006
Posts: 109

I have a sample application which has a page where in we can upload some records in database. When I deploy the war file in Tomcat(with data sources defined in conf/server.xml), everything works fine.

I want to try the same with Glassfish Enterprise server v2.1. I deployed the war file successfully using the GUI provided by the Glassfish server. However I get the below error when I test the connection (after creating the Connection pool):

Error casting to javax.sql.Datasource :{0} java.lang.ClassCastException: oracle.jdbc.driver.OracleDriver at com.sun.gjc.spi.DSManagedConnectionFactory.getDataSource( at com.sun.gjc.spi.DSManagedConnectionFactory.createManagedConnection( at com.sun.enterprise.connectors.ConnectorConnectionPoolAdminServiceImpl.getUnpooledConnection( at com.sun.enterprise.connectors.ConnectorConnectionPoolAdminServiceImpl.testConnectionPool( at com.sun.enterprise.connectors.ConnectorRuntime.testConnectionPool

This is what I am using to connect to database:
General Settings:
Name: jdbc/myapp
Datasource Classname: oracle.jdbc.driver.OracleDriver (I have placed ojdbc14.jar in the Sun\AppServer\lib\ directory)
Resource Type: javax.sql.DataSource

Advaced: user: XX
password: XX
URL: <<IP of the database server>> I am using oracle 11i
databaseName: SIDName
portNumber: <<port>>

I did check the sample database configuration at Sun\AppServer\lib\install\templates\resources\jdbc but was unsuccessful in creating the connection.
Am I missing anything?Any other properties I need to add in Advance settings? I was using the GUI provided by the Glassfish server.
Any variable I need to set?
Do I need to create JNDI name first and then connection pool? If so which one I need to create? CUstom or external resource?
Do I need to set any class path setting for the jar file I have added?

Any help on this issue would be appreciated.

K Kiran Kumar
Ranch Hand

Joined: Jan 04, 2006
Posts: 109

I have found a solution for my issue. I have created the connection pool with the following parameters through the GUI of GlassFish server:

General Settings:
Name: jdbc/myapp
Datasource ClassName: oracle.jdbc.pool.OracleDataSource
Resource type: javax.sql.DataSource

Advanced settings:
user: <<username>>
password: <<pwd>>
databaseName: mySID
portNumber: 1599
URL: jdbcracle:thin:@IPADDRESS:1599:mySID

With the above settings, if I ping to the database(from the GUI of GlassFish Server), the ping is successful.I did create a Resource pool with the same name i.e., jdbc/myapp.

Do create a <resource-ref> in deployment descriptor(web.xml)

With the below code, I was able to get the connection object successfully.
Context i = new InitialContext();
Context e = (Context) i.lookup("java:/comp/env");
DataSource d = (DataSource) e.lookup("jdbc/myapp");
con = (Connection)d.getConnection();
return con;

Thanks for your support.

komarios marios

Joined: Dec 14, 2009
Posts: 4
There is a simple tutorial for creating an oracle connection pool in Glassfish 2.1.1 here :
I agree. Here's the link:
subject: Connectin pool in GlassFish
jQuery in Action, 3rd edition