File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes DataSource implementation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "DataSource implementation" Watch "DataSource implementation" New topic

DataSource implementation

shishir gupta

Joined: Apr 30, 2004
Posts: 28
Using Tomcat3.1 and JBoss3.2.3. Want to deploy this application on JBoss.

Registered the datasource with a JNDI naming service.


import javax.naming.*;
import javax.sql.*;
import java.sql.*;

public class Connect{

String stat="Not connected";
public void init() {
Context ctx=new InitialContext();
if(ctx==null) throw new Exception("no context");

DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/BooksDB");
if(ds!=null) {
Connection con=ds.getConnection();
stat="Got connection " +con.toString();
} catch(Exception e) {e.printStackTrace();}

public String getStat() {
return stat;


I have put this class file in WEB-INF/classes folder.

In web.xml i made the following entries:

<description>JDBC Test Application </description>
<description>DB Connection</description>

This is the jsp page from which i am trying to test my connection.

<head><title> Connection Test </title></head>
Connect conn=new Connect();
<h3>Connection Result </h3>
<%=conn.getStat() %>

when i run this jsp page i get an error "Not connected"

javax.naming.NameNotFoundException: No object bound for java:comp/env/jdbc/BooksDB
at javax.naming.InitialContext.lookup(Unknown Source)
at example.jdbcExample.Connect.init(
at jsp._0002fjsp_0002fconnect_0002ejspconnect_jsp_0._jspService(_0002fjs
at org.apache.jasper.runtime.HttpJspBase.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(
at org.apache.jasper.servlet.JspServlet.serviceJspFile(
at org.apache.jasper.servlet.JspServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.tomcat.core.ServletWrapper.doService(
at org.apache.tomcat.core.Handler.service(
at org.apache.tomcat.core.ServletWrapper.service(
at org.apache.tomcat.core.ContextManager.internalService(
at org.apache.tomcat.core.ContextManager.service(
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnectio
at org.apache.tomcat.service.TcpWorkerThread.runIt(
at org.apache.tomcat.util.ThreadPool$
at Source)
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
javax.naming.NameNotFoundException: No object bound for java:comp/env/jdbc/BooksDB

I have no idea about JBoss but from the exception description it is clear that you haven't bound the Datasource object with java:comp/env/jdbc/BooksDB JNDI Name. See your container documentation to do this.
I agree. Here's the link:
subject: DataSource implementation
It's not a secret anymore!