Saturday, June 8, 2013

Glassfish JDBC resource pool error (classname missing)




View Page | Edit Page | Details
Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource

If you get this error when trying to ping a newly created JDBC connection pool from within GlassFish admin console, it's likely because you're missing the JDBC driver mysql-connector-java-5.1.*-bin.jar under the lib/ext folder on your domain.


To fix it copy that file there (e.g. ~/glassfish-v2ur2/domains/domain1/lib/ext/mysql-connector-java-5.1.5-bin.jar ), restart the domain and try again.


zhengyuan's note:

(1) place mysql-connector-java-5.1.*-bin.jar under %glassfish_home_dir%/domains/domain1/lib
(some people said %%/lib/ext, which appears to be wrong!!)
You don’t need to do anything in Descriptor files!
(2) The Glassfish plug-in for Eclipse is located in:

/home/zhengyuan/.eclipse/org.eclipse.platform_3.7.0_1075413907/plugins/oracle.eclipse.runtime.glassfish_3.1.0.0/glassfish3/glassfish

Please check Eclipse -> Window -> Preference -> Server -> Run time server -> Edit.

(3) You can either use GUI or use command line to create a JDBC pool or JDBC resource. This is commandline:-

./asadmin create-jdbc-connection-pool --datasourceclassname=com.mysql.jdbc.jdbc2.optional.MysqlDataSource --restype=javax.sql.DataSource --description "A JDBC connection pool by zhengyuan." --property User=mysql:Password=mysql:DatabaseName=ngs:Port=3306:ServerName=localhost "wzyPool"

./asadmin create-jdbc-resource --connectionpoolid "wzyPool" --description "A JDBC resource by zhengyuan" jdbc/mytest

./asadmin ping-connection-pool wzyPool

NOW, deploy your EJB module a sfollows:
(1)   In Eclipse, create your EJB project with a wrapping EAR project, then create your EJB session beans with JDBC code (my example: ZooWeb project);
(2)   Eport your EJB project as WAR archive to your local file system (xx.war);
(3)   Start your Glassfish on your new server (with mysql-connector-xxx.jar in its %%/lib folder);
(4)   From its admin console (localhost:4848), create the connection pool and the corresponding data source as shown earlier;
(5)   Ready to deploy: %%/asadmin deploy xx.war
Success! Now you can test your program via your browser. Enjoy!



(2) Another error and solution:
If you installed Jenkins and automatically started Jenkins service on boot, then Glassfish (or whatever web server will fail to start, with an error message “CREDENTIAL ERROR”). All web servers, whether installed under Linux OS or plugged into Eclipse, will fail the same way.

Solution: Stop Jenkins before you run the web server!
Redhat/CentOS:  #chkconfig Jenkins off
Debian/Ubuntu: #sysv-rc-conf Jenkins off

(3) Another error and solution:
If you get an error "Communication link failure", "Connection refused", and
command "./asadmin ping-connection-pool failed":
Possible problem: Mysql setup issue.
Please check mysql setup /etc/mysql/my.cnf and make sure the bind_address = 127.0.0.1 (NOT outside IP like 192.168.x.x)


No comments:

Post a Comment