• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Exception while using JNDI resources

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
I'm a lumberjack and I'm okay, I sleep all night and work all day. Lumberjack ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic