Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Help -javax.naming.NameNotFoundException: Name jdbc is not bound in this

843841Apr 21 2003 — edited May 9 2008
hi,
I am using JDBC to connect to to MS sql server.
I got Exception
"Naming exception in JNDIDatabase init
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context "

The code:
public void init(ServletConfig config) throws ServletException {

super.init( config);
try {

Connection conn= null;

Context ctx = new InitialContext();
Context env = (Context)ctx.lookup("java:comp/env");
DataSource ds = (DataSource) env.lookup("jdbc/Northwind");


conn = ds.getConnection("guest", "guest");
} catch(NamingException e) {
this.log("Naming exception in JNDIDatabase init", e);
e.printStackTrace();
} catch(SQLException e) {
this.log("SQL exception in JNDIDatabase init", e);
e.printStackTrace();
}
}

----------------------------
Server.xml

<Environment name="simpleValue" override="true" type="java.lang.Integer" value="30"/>
<Resource auth="Container" description="User database that can be updated and saved" name="UserDatabase" scope="Shareable" type="org.apache.catalina.UserDatabase"/>
<Resource name="jdbc/Northwind" scope="Shareable" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/Northwind">
<parameter>
<name>validationQuery</name>
<value>select * from PRODUCTS</value>
</parameter>
<parameter>
<name>url</name> <value>jdbc:microsoft:sqlserver://myhost:1433;DatabaseName=Northwind</value>
</parameter>
<parameter>
<name>password</name>
<value>guest</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbcx.sqlserver.SQLServerDataSource</value>
</parameter>
<parameter>
<name>username</name>
<value>guest</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
</ResourceParams>

<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved">
</Resource>
<ResourceParams name="UserDatabase">
<parameter>
<name>factory</name>
<value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
</parameter>
<parameter>
<name>pathname</name>
<value>conf/tomcat-users.xml</value>
</parameter>
</ResourceParams>
</GlobalNamingResources>

----------------------------------

The exception :

TestDynamicJDBC: Naming exception in JNDIDatabase init
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:811)
at org.apache.naming.NamingContext.lookup(NamingContext.java:194)
at com.blz.I3.portal.web.control.TestDynamicJDBC.init(TestDynamicJDBC.java:24)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:934)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:821)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3420)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3608)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:821)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:807)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:579)
at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:257)
at org.apache.catalina.core.StandardHost.install(StandardHost.java:772)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:569)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:411)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:879)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:368)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:166)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1196)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:738)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:347)
at org.apache.catalina.core.StandardService.start(StandardService.java:497)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:2189)
at org.apache.catalina.startup.Catalina.start(Catalina.java:512)
at org.apache.catalina.startup.Catalina.execute(Catalina.java:400)
at org.apache.catalina.startup.Catalina.process(Catalina.java:180)
at java.lang.reflect.Method.invoke(Native Method)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:203)


10x,
Tsafrir.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 6 2008
Added on Apr 21 2003
7 comments
2,754 views