*
The moose likes Tomcat and the fly likes DataBase Connection via DataSource using Oracle 10g and tomcat 6 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "DataBase Connection via DataSource using Oracle 10g and tomcat 6" Watch "DataBase Connection via DataSource using Oracle 10g and tomcat 6" New topic
Author

DataBase Connection via DataSource using Oracle 10g and tomcat 6

Atharva Gupta
Greenhorn

Joined: Jun 06, 2012
Posts: 16
can any body let me know that, is there any need of below code in web.xml file, for connecting oracle 10g database via DataSource using tomcat 6.



<resource-ref>
<description>Oracle Datasource example</description>
<res-ref-name>jdbc/myoracle</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>


or what other configurations are req. to connect with database oracle 10g via DataSource.

Regards
Atharva.
Sachin Pachari
Ranch Hand

Joined: Jan 16, 2012
Posts: 56

This will be part of Web.xml, this will refer to the Resource name which is defined in the server.xml, so the referrence must be added in the web.xml and there must be a definiton for the resource in the server.xml

I think you are also able to add this in the context.xml. so you might want to check the below link to know in detail about this.

http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html

In general the way to define your datasource will depend on the type of project and the type of frame-work, in your case i am guessing it is required in the web.xml

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16022
    
  20

To qualify Sachin's response: define the database connection pool in the "context.xml" file if this pool will only be used for a single webapp (the webapp that the Context definition defines). Define it in server.xml only if the same pool is common to more than one webapp.

I said "context.xml" in quotes, because the name of that file can vary depending on where it's located, but that's not something specific only to database connections.


Customer surveys are for companies who didn't pay proper attention to begin with.
Atharva Gupta
Greenhorn

Joined: Jun 06, 2012
Posts: 16
Hello All,

Actually what i have done,

1. i have added ojdbc14.jar in tomcat 6 lib directory.
2. i have added entry in context.xml, code is below.

<Resource name="jdbc/myoracle" auth="Container"
type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
url="jdbcracle:thin:@localhost:1521rcl"
username="dbunit" password="dbunit" maxActive="20" maxIdle="10"
maxWait="-1"/>

i have not done any entry in web.xml, but i have seen entry in web.xml in so many documents.

but ibnspite of adding entry in web.xml, i am able to connect to the database using the datasource config, in context.xml
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: DataBase Connection via DataSource using Oracle 10g and tomcat 6