aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes Retrieving datasource from jndi in java studio creator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Retrieving datasource from jndi in java studio creator" Watch "Retrieving datasource from jndi in java studio creator" New topic
Author

Retrieving datasource from jndi in java studio creator

Kerry Wilson
Ranch Hand

Joined: Oct 29, 2003
Posts: 254
I am having a problem retrieving a data source configured through Sun Java Studio Creator, I went through the xml files and the resource is named jdbc/mysql. So I used the code:

Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/mysql");

But this code, which works in my other applications is returning throwing a NameNotFoundException. Here is the creator created deployment descriptor segment:

<resource-ref>
<description>Rave generated DataSource Reference</description>
<res-ref-name>jdbc/mysql</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

and from sun-web.xml:

<resource-ref>
<res-ref-name>jdbc/mysql</res-ref-name>
<jndi-name>jdbc/mysql</jndi-name>
<default-resource-principal>
<name>username</name>
<password>password</password>
</default-resource-principal>
</resource-ref>

Is there anything that I am doing wrong, I have not had any problems with this before, using Netbeans / Tomcat so I am wondering if there is a difference between Sun AppServer and Tomcat.

thanks,

Kerry


http://www.goodercode.com
SCJP 1.4
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31075
    
233

Kerry,
NameNotFoundExceptions also occur when the datasource or connection factory is not found. You may want to look at the classpath too. Also, are there any errors in the server logs?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Kerry Wilson
Ranch Hand

Joined: Oct 29, 2003
Posts: 254
I do not see how it could not find javax.sql.datasource, as for the factory it does not seem that the creator has one configured, is their a default or is there some way I can specify one. ( I usually use Commons DBCP ) Thanks for any help.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31075
    
233

Kerry,
javax.sql.Datasource is the interface. The database driver provides a specific implementation. For example, it is classes12.jar in Oracle.
Kerry Wilson
Ranch Hand

Joined: Oct 29, 2003
Posts: 254
So that seems to be one of my problems, however the IDE is not even referencing the mysql driver nor is it including the mysql jar, even though I have added it to the project and added the datasource. It seems to me that Java Studio Creator has poor support for configuring the context, does anyone know how to do this?

I may just have to do it the ugly way, without using JNDI.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retrieving datasource from jndi in java studio creator