Solved

Datasource in Tomcat

Posted on 2006-07-13
15
890 Views
Last Modified: 2013-11-24
Can anyone help me create a datasource in Tomcat? I'm running version 5.5.9, the one included with Netbeans 5.0

I've followed http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html

Here's my server.xml

<Resource name="jdbc/publicommon" auth="Container"
    type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
    url="jdbc:oracle:thin:@peanut:1521:pad"
    username="***" password="***" maxActive="20" maxIdle="10"
    maxWait="-1"/>

My web.xml

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


Yet I still get

java.lang.ExceptionInInitializerError: Could not find datasource



Honestly, if I could line up the tomcat devs......... it's unreal trying to get this thing working.
0
Comment
Question by:cormierg1
  • 6
  • 5
  • 3
15 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 17099009
How do you retrieve the datasource? Try changing the name to somethign that does not contain / and try again
0
 

Author Comment

by:cormierg1
ID: 17099081
It's with Hibernate.

String datasourceName = "jdbc/publicommon";
toolConfiguration.setProperty("hibernate.connection.datasource", datasourceName);


I've had no issues with the slash in Websphere, and all the online documents use one as well..
0
 
LVL 35

Expert Comment

by:girionis
ID: 17099153
Ok I see. Your config code looks file. What is the toolConfiguration?
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 8

Expert Comment

by:colr__
ID: 17099155
Are you coding doing this manually? Netbeans will generate all the code you need to make the connection, if thats any use. As long as you have the datasource listed in the runtime panel, then right click in your source code and select 'use datasource' or something like that.
0
 

Author Comment

by:cormierg1
ID: 17099160
Yes, I am coding all of this manually.
0
 
LVL 8

Expert Comment

by:colr__
ID: 17099190
Could you try doing it via netbeans and check the code it produces? Its quite concise, so its a good starting point to have a working version. In future projects, youll find it a lot easier using netbeans to do this kind of plumbing for you anyway. When I started with this kind of stuff I found myself banging my head against my desk so often, because I couldnt get the 'simple' examples to work. In the end I started using the automated tools via the IDE I was using - the time I spent banging my head made me understand enough about the whole process in general though to go in and make changes to the XML etc.
0
 

Author Comment

by:cormierg1
ID: 17099200
How do I do this?

Under runtime I've added my Oracle driver, and added a database to my database tab but I see no option to include it as a datasource.
0
 

Author Comment

by:cormierg1
ID: 17099357
I might be one step closer...


Caused by: java.sql.SQLException: No suitable driver
        at java.sql.DriverManager.getDriver(DriverManager.java:243)
        at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:773)
        ... 26 more


Where do I put my ojdbc14.jar? I tried

netbeans/enterprise2/jakarta-tomcat-5.5.9/common/lib
and
netbeans/enterprise2/jakarta-tomcat-5.5.9/server/lib

but it still doesn't pick it up?
0
 
LVL 35

Expert Comment

by:girionis
ID: 17099519
Try a different driver. The ojdbc is probably for the odbc bridge.
0
 

Author Comment

by:cormierg1
ID: 17099570
No, ojdbc14.jar is the Oracle JDBC driver.

ojdbc14.jar
Classes for use with JDK 1.4. It contains the JDBC driver
classes, except classes for NLS support in Oracle Object and
Collection types.
0
 
LVL 35

Expert Comment

by:girionis
ID: 17099603
Then the driver url is wrong. Are you sure you can connect with this form of url: jdbc:oracle:thin:@peanut:1521:pad ?
0
 

Author Comment

by:cormierg1
ID: 17099798
Yes. This is the same connection URL my Websphere datasource uses and it works perfectly.
0
 
LVL 35

Expert Comment

by:girionis
ID: 17099864
Try to register the driver: Class.forName("oracle.jdbc.OracleDriver"); if you have access to the initialization code.
0
 
LVL 8

Accepted Solution

by:
colr__ earned 75 total points
ID: 17099865
With your driver and database visible in the runtime tab on Netbeans, right click somewhere in your code and select 'Enterprise resopurces > Use database'. This will propbably only work in a sertvlet or EJB, as you shouldnt really be using databases from JSPs (although you can use the same code you use in a servlet once Netbeans has generated it.
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to convert String matching to regex in java 4 50
expectj telnet failing 5 45
hibernate example for saving data 19 55
American Express @Work site and Java 4 29
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question