This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connectin pool in GlassFish

 
K Kiran Kumar
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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(DSManagedConnectionFactory.java:139) at com.sun.gjc.spi.DSManagedConnectionFactory.createManagedConnection(DSManagedConnectionFactory.java:93) at com.sun.enterprise.connectors.ConnectorConnectionPoolAdminServiceImpl.getUnpooledConnection(ConnectorConnectionPoolAdminServiceImpl.java:1315) at com.sun.enterprise.connectors.ConnectorConnectionPoolAdminServiceImpl.testConnectionPool(ConnectorConnectionPoolAdminServiceImpl.java:551) 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.

Regards,
Kiran.
 
K Kiran Kumar
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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)
<resource-ref>
<res-ref-name>jdbc/myapp</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

With the below code, I was able to get the connection object successfully.
try
{
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.

Regards,
Kiran.
 
komarios marios
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a simple tutorial for creating an oracle connection pool in Glassfish 2.1.1 here :

http://mariosgaee.blogspot.com/2009/12/oracle-connection-pool-in-glassfish.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic