• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to let non-web components use J2EE JNDI Datasources?  RSS feed

 
Steven Ostrowski
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone!
I'm trying to use the JNDI server that is in the J2EE server, but I'm trying to access it from a separate Java application. In particular, I'm trying to use the Datasource method of retrieving a connection. Basically what I want to do is be able to administratively add a Datasource like you do with j2eeadmin, but I want the Datasource to be usable by non-web components. I want an application client to be able to use j2ee's JNDI provider, lookup, and USE the datasource bound in the directory.
I installed the mm.mysql driver in $JAVA_HOME/jre/lib/ext so that it's in the CLASSPATH. Then, I used j2eeadmin -addJdbcDriver <drivername>, and then j2eeadmin -addJdbcDatasource jdbc/MY_DB <mysql:url>.
It seems like things are set up correctly because the same problem occurs for the built-in Cloudscape Datasource as well.
The problem is:
When I try to write a separate Java application that does:
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup("jdbc/MY_DB");
Connection c = ds.getConnection();
It gives me:
java.sql.SQLException: This DataSource object can only be used by J2EE components or application clients.
If I instead do ic.lookup("java:comp/env/jdbc/MY_DB");, it tells me that no object is bound to that name.
Why would the Datasource object only be accessible by J2EE components or app clients? Isn't what I'm writing an app client anyway?
Help would be greatly appreciated as I'd like to use the preferred connection method, not the DriverManager method.
Thanks!
 
Byron Estes
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steven,
The issue is that DataSource object you are looking up is not "Remotable". When they refer to J2EE objects, they are talking about ejb or other objects that support Remote Invokation. That requires the implementation of stubs/skelletons to handle communication between your application and the remote object usually as RMI/IIOP.
Regards,
 
Steven Ostrowski
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to administratively add a JdbcDatasource to be bound and accessible to non-j2ee components at the j2ee server's startup then?
I also do not fully understand what you said. Both the included Cloudscape and mm.MySQL drivers give the same error when trying to connect. It seems like the j2ee server has some sort of security mechanism that only allows components deployed in it to access datasources administratively added.
thanks for the reply
 
Byron Estes
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe you would need to establish a stand alone JNDI service.
 
Byron Estes
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to check out this article...
click here for article
 
Mon Mayor
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good point. I was actually thinking about the same thing. I wrote a jndi client that lists out all the objects listed in a server and I did not find the datasources. So the datasources are not stored as objects. I wonder what is happening inside. My guess is that even though there is a jndi name for the datasource it is not a remote object and there is only a local reference to the instance. It is just a non corba, non rmi interface and hence cannot be accessed remotely as such.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!