javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
843854Jul 25 2002 — edited Jul 31 2002Hello everyone,
I am getting the following error when I try to use a datasource in tomcat 4.1.
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
I have set my classpath correctly for all environment variables such as J2EE_HOME and JAVA_HOME and CATALINA_HOME. The necessary jars are all included in the classpath. I have inserted the following xml tags and values into the server.xml file for tomcat:
<Context path="" docBase="ROOT" debug="0"/>
<Resource name="jdbc/JUNK" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/JUNK">
<parameter>
<name>user</name>
<value>username</value>
</parameter>
<parameter>
<name>password</name>
<value>mypassword</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>driverName</name>
<value>jdbc:oracle:thin:@205.12.174.14:1500:JUNK</value>
</parameter>
</ResourceParams>
In my web.xml file I have included the following:
<resource-ref>
<description>
</description>
<res-ref-name>
jdbc/JUNK
</res-ref-name>
<res-type>
javax.sql.DataSource
</res-type>
<res-auth>
Container
</res-auth>
</resource-ref>
In my Java code I call the jndi as follows:
public void calculateTimeStamp() {
try {
Connection conn = null;
Statement stmt = null;
Context ctx = null;
DataSource ds = null;
ctx = new InitialContext();
Context envCtx = (Context) ctx.lookup("java:comp/env");
ds = (DataSource) envCtx.lookup("jdbc/JUNK");
conn = ds.getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT timestamp FROM table");
while(rs.next()) {
cal.setTime(rs.getDate(1));
timestamp = months[cal.get(Calendar.MONTH)] + " " + cal.get(Calendar.DATE) + ", " + cal.get(Calendar.YEAR);
}
rs.close();
stmt.close();
conn.close();
} catch(SQLException ex) {
System.out.println(ex);
} catch(Exception e) {
System.out.println(e);
}
}
Any suggestion as to what could be wrong?