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.
oscarlgAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vzilkaCommented:
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.
oscarlgAuthor Commented:
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.
vzilkaCommented:
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.
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

oscarlgAuthor Commented:
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).
vzilkaCommented:
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.
oscarlgAuthor Commented:
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.

:)
vzilkaCommented:
You don't need to build your orion-web.xml file by hand - this is done by Oracle9iAS automatically.
You do need a web.xml file (in the WEB-INF directory) which will contain the welcome-file-list tag:
<welcome-file-list>
          <welcome-file>/query.html</welcome-file>
</welcome-file-list>
and a servlet-mapping tag:
<servlet>
  <servlet-name>DeptListServlet</servlet-name>
  <servlet-class>deptdemo.DeptListServlet</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>DeptListServlet</servlet-name>
  <url-pattern>/deptListServlet</url-pattern>
</servlet-mapping>

You put the application.xml file inside the META-INF directory. This is a basic example:
<application>
  <display-name>DeptAppMP</display-name>
  <module>
    <ejb>EJB</ejb>
  </module>
  <module>
    <web>
      <web-uri>WEB</web-uri>
      <context-root>/DeptAppMP</context-root>
    </web>
  </module>
</application>

When you deploy this application in Oracle9iAS, the mapping of the URL will be displayed automatically in the OEM, so it should be very easy for your deployer to use.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
oscarlgAuthor Commented:
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.....
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Application Servers

From novice to tech pro — start learning today.