• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to let non-web components access J2EE JNDI Datasources?

 
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!
 
mister blinky
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you solve this? I'm actually curious about this same issue ....


Originally posted by Steven Ostrowski:
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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!