| Author |
Retrieving datasource from jndi in java studio creator
|
Kerry Wilson
Ranch Hand
Joined: Oct 29, 2003
Posts: 251
|
|
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
internet detective
Marshal
Joined: May 26, 2003
Posts: 26168
|
|
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: 251
|
|
|
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
internet detective
Marshal
Joined: May 26, 2003
Posts: 26168
|
|
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: 251
|
|
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.
|
 |
 |
|
|
subject: Retrieving datasource from jndi in java studio creator
|
|
|