• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DataSource implementation

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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() {
try{
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();
if(con!=null){
stat="Got connection " +con.toString();
con.close();
}
}
} 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>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/BooksDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>


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

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

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 com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:116)
at javax.naming.InitialContext.lookup(Unknown Source)
at example.jdbcExample.Connect.init(Connect.java:15)
at jsp._0002fjsp_0002fconnect_0002ejspconnect_jsp_0._jspService(_0002fjs
p_0002fconnect_0002ejspconnect_jsp_0.java:63)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:296)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:369)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:368)
at org.apache.tomcat.core.Handler.service(Handler.java:261)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:356)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:720)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:666)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnectio
n(HttpConnectionHandler.java:194)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:403)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Unknown Source)
--------------------------------------------
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic