my dog learned polymorphism*
The moose likes Tomcat and the fly likes Exception while using JNDI resources Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Exception while using JNDI resources" Watch "Exception while using JNDI resources" New topic
Author

Exception while using JNDI resources

surendar prabu
Ranch Hand

Joined: Jul 24, 2006
Posts: 102
I have configured my database connections using JNDI resources of Tomcat5.0 server. Ihave followed all the steps of Tomcat configuration and when i run the application i get the following exception \

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

my code is as follows

<%@page contentType="text/html" import="java.sql.*,javax.sql.*,java.io.*,javax.naming.*"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%
Connection con1=null,con2=null;
Statement st2=null;
ResultSet rs2 = null;
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>DBTest Page</title>
</head>
<body>
<%
try
{
Context initContext = new InitialContext();
DataSource ds = (DataSource)initContext.lookup("jdbc/javatest");
con2 = ds.getConnection();
st2 = con2.createStatement();
rs2 = st2.executeQuery("SELECT * from tabusers"); %>
<table>
<caption><%= con2.toString() %></caption>
<tr><th>User</th><th>Password</th></tr>
</table>
<div style="overflow:auto; width: 615px; height:180px;">
<table>
<% while(rs2.next())
{%>
<tr><td><%=rs2.getString(3)%></td>
<td><%=rs2.getString(4)%></td></tr>
<%}
%>
</table>
</div>
<%
}
catch(NamingException ne)
{
%> <%= ne %>
<% }

catch(SQLException se)
{
%> <%= se %>
<% }
finally {
// Always make sure result sets and statements are closed,
// and the connection is returned to the pool
if (rs2 != null) {
try { rs2.close(); } catch (SQLException e) { ; }
rs2 = null;
}
if (st2 != null) {
try { st2.close(); } catch (SQLException e) { ; }
st2 = null;
}
if (con2 != null) {
try { con2.close(); } catch (SQLException e) { ; }
con2 = null;
}
}

%>

</body>
</html>


the same code is working fine with Sun Application Server


SCJP 1.4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception while using JNDI resources
 
Similar Threads
error invalid column name
Object has been closed
Sending Email from jsp page
Object has been closed
How to display Dynamic Menus and sub-menus using <s:iterator> tag in struts