Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Datasource configuration in Tomcat

 
Srikant Venkata
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am trying to configure the Datasource in Tomcat 6.0 using a context.xml file.
I am using Oracle 10g as Database.
I have placed the below changes inside /META-INF/context.xml

<Context>
<Resource auth="Container" name="jdbc/loginApp" type="javax.sql.DataSource"
description="Login Application" driverClassName="oracle.jdbc.OracleDriver"
maxActive="100" maxIdle="10" maxWait="10000" password="l0g1napp"
url="jdbcracle:thin:@localhost:1521:xe" username="loginapp" />
</Context>

In My application, I am trying to do lookup using the below code for lookup name as "loginApp".


Context initContext = new InitialContext();
Context envContext = (Context) initContext.lookup("java:/comp/env");
DataSource ds = (DataSource) envContext.lookup("jdbc/" + streamName);

But, When I run the application, I get the below error

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
at com.myapp.Utilities.Datastreams.getConnection(Datastreams.java:16)
at com.myapp.Controller.LoginController.ValidateLogin(LoginController.java:68)
at com.myapp.Controller.LoginController.doPost(LoginController.java:49)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

What more configurations should I follow such that my application picks up the context.xml. Should I add any reference to context.xml in my Web.xml?

-Regards
Srikant Mantha
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to add the Oracle driver JAR file in either your application's lib folder, or in Tomcat's lib folder.
 
Srikant Venkata
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, It works now when I added the jar file in Tomcat Server Libs. Earlier I had added only to the Application's Build path.

-Regards
Srikant Mantha
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic