permaculture playing cards*
The moose likes Tomcat and the fly likes Tomcat and datasource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat and datasource" Watch "Tomcat and datasource" New topic
Author

Tomcat and datasource

Jasvir Rupana
Ranch Hand

Joined: Oct 13, 2010
Posts: 52
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 ?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15960
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Misha Ver
Ranch Hand

Joined: Mar 03, 2008
Posts: 470
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

Joined: Oct 13, 2010
Posts: 52
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

Joined: Oct 13, 2010
Posts: 52
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tomcat and datasource
 
Similar Threads
javax.naming.NamingException: Cannot create resource instance
Deploying application updates in tomcat. - a pain.
Problem with @Resource annotation (without web.xml)
updating
Tomcat Start up issue: SEVERE: Error listenerStart