users@glassfish.java.net

Database connection in GlassFish server

From: <glassfish_at_javadesktop.org>
Date: Thu, 02 Apr 2009 04:06:29 PDT

Hi,

I have myapp.war, which is a simple web application developed using struts 1.1 framework in Eclipse. The application has a jsp page, which is used to upload data(user info) to Oracle database. I have deployed myapp.war in Tomcat with data sources defined in Tomcat/conf/server.xml. The application works fine. I want to repeat the same in GlassFish 2.1 server.
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: jdbc:oracle:thin:@IPADDRESS:1599:mySID

With the above settings, if I ping to the database(from the GUI of GlassFish Server), the ping is successful. But from the code, I use the following to get the connection object which was unsuccessful:
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;
}
                        
I have placed the ojdbc14.jar file in the lib directory.

(1) From Tomcat server I use oracle.jdbc.driver.OracleDriver to connect to database which was successful. But here in GlassFish, I have to use oracle.jdbc.pool.OracleDataSource instead of oracle.jdbc.driver.OracleDriver to ping successfully. Am I defining the data sources/Connection pool correctly?
(2) Is there any flaw in my code to get the connection object? Any thing am I missing? Do I need to set any variables/parameters/paths/classpath's?
Can someone please assist me in this issue.
Thanks in advance.

Regards,
Kiran.
[Message sent by forum member 'kkiran' (kkiran)]

http://forums.java.net/jive/thread.jspa?messageID=340242