Forums Register Login

How to: DataSource in tomcat 5 with netBeans 5

+Pie Number of slices to send: Send
Hi All - this is an fyi post.

To use a JNDI/JDBC DataSource with Tomcat 5.5 and netBeans 5 do the following:

From the netBeans 'Runtime' tab go to the tomcat web server and start up the admin console. Create your data source there. For Oracle mine looks like:

url:
jdbc racle:thin:@//localhost:1521/JIEDDO

driver:
oracle.jdbc.driver.OracleDriver

Make sure you download the ojdbc14.zip from Oracle and CHANGE THE NAME TO
ojdbc14.jar --- tomcat will NOT pick a .zip file.

Place ojdbc14.jar in the TOMCAT dir common/lib

You should now have an entry in your server.xml file that looks like:

............
<Resource
name="jdbc/orclJIEDDO"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
password="xxxxx"
maxIdle="2"
maxWait="5000"
username="scott"
url="jdbc racle:thin:@//localhost:1521/JIEDDO"
maxActive="4"/>
</GlobalNamingResources>

Leave it that way.

Now. Go back to the Projects tab in netBeans and edit your web.xml file - add this tag

IMPORTANT - DO NOT double click a .xml file from netBeans and edit it....the changes won't take. Instead you MUST select the file, right-click and select 'Edit'. This is a known 'feature' of netBeans 5.

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

Next. Edit your context.xml file - it should look like this:

<Context path="/JIEDDO">
<ResourceLink name="jdbc/orclJIEDDO"
type="javax.sql.DataSource"
global="jdbc/orclJIEDDO"/>
</Context>

Last - almost there. Add this code to your java class:

Context ctx = new InitialContext();
DataSource dataSource = (DataSource)
ctx.lookup("java:comp/env/jdbc/orclJIEDDO");
Connection conn = dataSource.getConnection();

There. Done.

Good luck.

Amy
This guy is skipping without a rope. At least, that's what this tiny ad said:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3200 times.
Similar Threads
Crystal Reports: Error finding JNDI name
Crystal Reports XI and Sun One 6.1 web server SP 5 Error finding JNDI name
Whacky db problem.
Tomcat DataSource
Tomcat Database Connection Pooling Error
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 05:35:33.