• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Tomcat and datasource

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am trying to configure data source for tomcat application .while starting tomcat i am getting severe error as :

SEVERE: Null component Catalina:type=DataSource,path=/myApp,host=localhost,clas
s=javax.sql.DataSource,name="jdbc/myApp

in application i am calling it like :
DataSource ds = (DataSource)initCtx.lookup("java:comp/env/jdbc/myApp");
and when i run application following error occurs :

Name java: is not bound in this Context

In server.xml and web.xml i have done all the necessary changes .

Anyone any help please ?
 
Saloon Keeper
Posts: 23882
162
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you didn't code your getInitialContext() method call correctly, but you didn't show it, so I can't say what the problem is.
 
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jasvir Rupana wrote:In server.xml and web.xml i have done all the necessary changes



Why are you making changes in server.xml? Are you still using Tomcat 4?
 
Jasvir Rupana
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys for your response,
here's my initContext code

javax.naming.Context ctx = new javax.naming.InitialContext();
javax.sql.DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/Test");
java.sql.Connection con = ds.getConnection();

and i am using tomcat version 6
 
Jasvir Rupana
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any one any help please ,

java class code
--------------------------------------------------
Context context = new InitialContext();
this.ds = (DataSource)context.lookup( "jdbc/MySqlDS");

web.xml
------------------------------------------
<resource-env-ref>
<description>
DB Connection
</description>
<resource-env-ref-name>
jdbc/MySqlDS
</resource-env-ref-name>
<resource-env-ref-type>
javax.sql.DataSource
</resource-env-ref-type>
</resource-env-ref>

contextname.xml in tomcat catalina/localhsot
----------------------------------------------------
<Context path="/testDS"
reloadable="true" debug="0"
docBase="D:\J2EE\testProj"
workDir="D:\J2EE\testProj\work"
crossContext="true">

<Resource name="jdbc/MySqlDS"
auth="Container"
type="javax.sql.DataSource"
username="root"
password="password"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/sqldb"
maxActive="15"
maxIdle="3"
maxWait="5000"
removeAbandoned="true"
removeAbandonedTimeout="20"
logAbandoned="true"
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
validationQuery="select 1"
minEvictableIdleTimeMillis="3600000"
timeBetweenEvictionRunsMillis="1800000"
numTestsPerEvictionRun="10"
testWhileIdle="true"
testOnBorrow="true"
testOnReturn="false"
/>

error
----------------
Error while trying to start the database: javax.naming.NameNotFoundException: Name MySqlDS is not bound in this Context
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic