I had a similar problem with glassfishv3 and Netbeans 6.9.1. Finally this link provided a solution:
http://netbeans.org/kb/docs/web/mysql-webapp.html#prepareCommunication
MySql connection from a Glassfish web app was possible only after referencing the JDBC resource in web.xml. Seems that Glassfish needs to have a JDBC resource to MySQL first (and in turn this JDBC resource needs to point at a MySQL connection pool) and web-apps can access MySQL through that JDBC resource. So, the JDBC resource needs to exist in web.xml as well as on Glassfish.
Note: The mysql-connector-java-5.1.6-bin.jar needs to be in the lib folder of the glassfishv3 installation to setup the MySQL connection pool.
[Message sent by forum member 'hampkaushik']
http://forums.java.net/jive/thread.jspa?messageID=484817