• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Retrieving datasource from jndi in java studio creator

 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic