File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes How to: DataSource in tomcat 5 with netBeans 5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to: DataSource in tomcat 5 with netBeans 5" Watch "How to: DataSource in tomcat 5 with netBeans 5" New topic
Author

How to: DataSource in tomcat 5 with netBeans 5

A Saari
Greenhorn

Joined: Mar 31, 2006
Posts: 26
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to: DataSource in tomcat 5 with netBeans 5