• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tomcat and datasource

 
Jasvir Rupana
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • 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 ?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
Misha Ver
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic