Link to home
Start Free TrialLog in
Avatar of oscarlg
oscarlg

asked on

Oracle9ias OCJ4 Data Sources

I've developed a web project using struts on a Tomcat 3.3 server connected to an Oracle 8i DB.
In the Tomcat environment, the connection to the DB is made using the usual DriverManager.getConnection / thin driver and it works fine.

The production server is OiAs (OCJ4) and I want to setup a DataSource to use the pooled jdbc connections. After setting up the data-sources.xml, I guess that database connection related classes must be re-coded, can anybody explain me the steps that I must follow until the final EAR is generated, knowing that struts is involved?

Best regards and thanks in advance.

oscarlg.
Avatar of vzilka
vzilka

Hi Oscarlg,

1. The easiest thing to do is to configure the data-sources.xml file inside the OC4J_HOME\config directory.
You create a data source to your server through it. It will look similar to this:
     <data-source
          class="com.evermind.sql.DriverManagerDataSource"
          name="OracleDS"
          location="jdbc/OracleCoreDS"
          xa-location="jdbc/xa/OracleXADS"
          ejb-location="jdbc/OracleDS"
          connection-driver="oracle.jdbc.driver.OracleDriver"
          username="hr"
          password="hr"
          url="jdbc:oracle:thin:@localhost:1521:ORA9i"
          inactivity-timeout="30"
     />
Depending on your user name and SID name.

2. Then, your get the data-source through a lookup operation on the InitialContext object.
Try this line:
InitialContext ic = new InitialContext();
Since you are using the data-source through a servlet, you don't need to specify parameters for the InitialContext object.
Then do this:
DataSource ds = (javax.sql.DataSource)ic.lookup("jdbc/OracleDS");
(Assuming this is the name of your DataSource).

3. To get a connection to the database use the following line:
Connection conn = ds.getConnection();

This should do it.
Avatar of oscarlg

ASKER

Thanks for the copy-paste vzilka, but I also have the OAS how-to documentation ;)

Sorry for the joke. I guess that I've hadn't explained very well because my poor english... I've already done the connection and the changes in the datasource.xml. My problem is the generation of the EAR file and the test of the connection in the deployed environment.

I know the files that must be created to performa a correct EAR deployment (application.xml, orion.web.xml) but not what information i must include to publish the application in a given directory.to test the connection.

I hope you can help me.
First of all, sorry about that. I thought this is what you were after.
About the deployment - You deploy your ear file in OC4J by using server.xml and http-web-site.xml. If you want information about these files - I'd be happy to show you how.
Testing the DB connection can only be done by your application. Why not write a small JSP that access the DataSource, deploy it in the default-web-app directory, and see if the connection works? Then you can go ahead with deploying the EAR file to OC4J.

BTW - if you have JDeveloper (free download) you can use it to deploy to OC4J, including all XML files and all DB connections.
Avatar of oscarlg

ASKER

The problem with jdev is the following:
It allows you to put the blank xml config files in the right places of your deployment directories but doesn't has any user-friendly tool to prepare the deployment with ears or wars (I don't have direct access to the production server).
Which JDeveloper version are you using?
903 (Which you can download from otn.oracle.com) allows you to select the XML file, right-click it in the project explorer, and select settings. This allows you to set properties in the XML file.
Avatar of oscarlg

ASKER

I'm using the same version JDev 9.0.3.
Perhaps my problem is that i don't know how to use the tools... :(

I'll try another extended explanation. I've my app working in a pre-production server but using the "directory deployment" that is: The jsp pages are in [oias]\home\default-web-app\myapp\, the jar containing the classes is the [oias]\home\default-web-app\myapp\web-inf\lib,  and i've redirected the default web app (changing the default_web_app in application.xml) to it.

Now, i want to generate the ear and war files to allow the production server administrator to perform a more "professional" deployment using the administration tools of O9iAS. What is the minimal configuration that I need to add to my META-INF\application.xml and the WEB-INF\orion-web.xml to configure the application name and the deployment directory (supposing that both of them are called myapp).

Hope I've explained.

Thanks for the effort.

:)
ASKER CERTIFIED SOLUTION
Avatar of vzilka
vzilka

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of oscarlg

ASKER

I've discovered that the problem with the deployment was not the xml configuration files but the inclusion of some jars with the ear files.

Thanks for your effort.

Best regards.....