Well, your suggestion will work but it is not the preferred way of doing the lookup. Your lookup should look something like this (taken from some production code):

connection = ((DataSource)(new InitialContext()).lookup("java:comp/env/jdbc/ordermanagementDB")).getConnection();

ejb-jar.xml would contain something like this:

<resource-ref>
<description>A jdbc connection to the order management Oracle DB</description>
<res-ref-name>jdbc/ordermanagementDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>


and finally jboss.xml would contain something like this:

  <resource-managers>
    <resource-manager>
      <res-jndi-name>java:/ordermanagementDB</res-jndi-name>
      <res-name>jdbc/ordermanagementDB</res-name>
    </resource-manager>
  </resource-managers>

The idea is to provide a logical resource name inside your Java code, then map the logical name to a physical name in the deployment descriptor. This allows you to change physical resources at deployment time without having to edit or recompile code.

Edgar Silva wrote:
Try the Lookup this way:
DataSource ds = (DataSource) jndiContext.lookup("java:/dbnrhdes");
I had been using DataSources in JBoss and everything is ok....
I hope help you
Edgar Silva


    ----- Original Message -----
    *From:* Paulo Francesco Pacheco <mailto:[EMAIL PROTECTED]>
    *To:* [EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]>
    *Sent:* Thursday, June 05, 2003 9:53 PM
    *Subject:* [JBoss-user] Problems with JBoss on JNDI Data Source
    Connection

Hi...
I have taken some exceptions with my JBoss...jboss-3.0.6_tomcat-4.1.18
...the client classpath is ok...
my jdk version is jdk1.3.1 and it�s ok...
I wrote a simple test code...
package com.ccibm.wiredsys.xclient;
import java.beans.Beans;
import java.io.IOException;
import java.io.Serializable;
import java.sql.Connection;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class SQLJndiConnectionTest extends Beans implements
Serializable {
public SQLJndiConnectionTest() {
}
public static void main(String[] args)
throws IOException, NamingException {
try {
Properties props = new Properties();
props.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
props.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
props.put("java.naming.provider.url","jnp://localhost:1099");
InitialContext jndiContext = new InitialContext(props);
DataSource ds = (DataSource)
jndiContext.lookup("java:/jdbc/dbnrhdes");
Connection conn = ds.getConnection();
if (conn != null || conn.isClosed() == false) {
System.out.println(
"Connection --> " + (int) conn.toString().hashCode());
conn.close();
ds = null;
jndiContext = null;
} else {
System.out.println("No active connections !!!");
}
} catch (Exception e) {
System.out.println("No active connections !!!");
e.printStackTrace();
throw new NamingException(e.getMessage());
}
}
}
and the exit message is the same all time...
No active connections !!!
javax.naming.NameNotFoundException: jdbc not bound
at
sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:245)
at
sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:220)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:484)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:463)
at javax.naming.InitialContext.lookup(InitialContext.java:350)
at
com.ccibm.wiredsys.xclient.SQLJndiConnectionTest.main(SQLJndiConnectionTest.java:29)
javax.naming.NamingException: jdbc not bound
at
com.ccibm.wiredsys.xclient.SQLJndiConnectionTest.main(SQLJndiConnectionTest.java:44)
Exception in thread "main"
someone can help me please !!!




--
Guy Rouillier




------------------------------------------------------- This SF.net email is sponsored by: Etnus, makers of TotalView, The best thread debugger on the planet. Designed with thread debugging features you've never dreamed of, try TotalView 6 free at www.etnus.com. _______________________________________________ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to