• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieving datasource from jndi in java studio creator

 
Kerry Wilson
Ranch Hand
Posts: 254
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33699
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Kerry Wilson
Ranch Hand
Posts: 254
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33699
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 254
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic