0

I am using Glassfish 4.0. I have set a connection pool to MySql. Every thing looks fine to get the correct pool with:

Context ctx =new InitialContext();
DataSource ds = ctx.lookup("jdbc/music");

but when I try to use it in a jsp page:

<sql:query var="result" dataSource="jdbc/music">

What I get is a connection to Derby Pool.

Any help?

ferrito
  • 339
  • 3
  • 9
  • Is it works like: @Resource(name="jdbc/music") DataSource ds; – Fireworks Jun 06 '14 at 09:08
  • It does not work using annotation to inject the resource referred to by it. It does not resolve the proper jndi name, and instead it uses jbdc/_default which refers to Derby pool – ferrito Jun 06 '14 at 13:02

1 Answers1

0

I'm not sure if this is a bug in GlassFish 4 or some kind of misconfiguration but to use a datasource in this way you have to define a resource reference either in your web.xml or in a context.xml.

The web.xml entry should look similar to this:

<resource-ref>
  <res-ref-name>jdbc/music</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
</resource-ref>

Make sure you haven set up the correct res-type for your configured datasource. If you already have something like this (I suppose because if I remove this entry I get a different error) or if this doesn't fix the problem you may have to set up the resource reference in glassfish-web.xml too. It should look similar to this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
  <class-loader delegate="true"/>
  <resource-ref>
    <res-ref-name>jdbc/music</res-ref-name>
    <jndi-name>jdbc/music</jndi-name>
  </resource-ref>
</glassfish-web-app>

See also:

Community
  • 1
  • 1
unwichtich
  • 13,712
  • 4
  • 53
  • 66
  • Thanks for your comment @unwichtich. Of course that I have the resource configured in web.xml. I already found the problem. The folowing line was missing in the resource-ref section in web.xml jdbc/music. It was not necessary in previous versions of Glassfish. I am just trying to find why is this necessary now. – ferrito Jun 08 '14 at 02:31