Java – GlassFish Server does not connect to SQL database (error w.r.t. SQL driver)

connectionglassfishjavanetbeanssql

I am using a brand new developing pc and need to test a personal application that runs on a local GlassFish server 3.1.2 and should connect with a local SQL database called 'funkOneDB' (my IDE is NetBeans 7.2.1). But I can't get the GlassFish server to connect with the database, and the problem seems to be related to the (place of the) SQL driver in the GlassFish Server's directories (more problem specifics in a few lines).

I am fairly certain I correctly set up the related JDBC Resource and Connection Pool on the GlassFish Server (as I mimic a set-up already existing and working properly on another developing pc).

The Resource specifics are:

  • jndi name: jdbc/FunkResource
  • pool name: FunkPool

The (most important) Pool specifics are:

  • pool name: FunkPool
  • resource type: javax.sql.Datasource
  • datasource classname: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
  • additional properties correspond to the specifics in the XML GlassFish-resources of the application (username, password, url, etc.; no problems there)

I first placed the necessary SQL driver in the GlassFish Server's directories, i.e. the file mysql-connector-java-5.1.18-bin.jar at ..\GlassFish3\GlassFish\domains\domain1\lib\ext.

Yet, when I perform a ping test from the JDBC Pool 'FunkPool' at the GlassFish server, I get the following error:

Ping Connection Pool failed for FunkPool. WEB9031: WebappClassLoader unable to load resource [com.mysql.jdbc.SQLError], because it has not yet been started, or was already stopped Please check the server.log for more details.

In the server.log I only find the following extra logging exception and failure info:

(i) Exception while creating an unpooled [test] connection for pool [ FunkPool ], WEB9031: WebappClassLoader unable to load resource [com.mysql.jdbc.SQLError], because it has not yet been started, or was already stopped

(ii) RestResponse.getResponse() gives FAILURE. endpoint = 'http://localhost:4848/management/domain/resources/ping-connection-pool.json'; attrs = '{id=FunkPool}'

Note however, that when I ping the database funkOneDB from my IDE NetBeans via jdbc:mysql://localhost:33066/funkOneDB, it's succesful. As already mentioned, the credentials and other data I use for this IDE-based ping are the same data I use in the JDBC Connection Pool.

I searched for the problem also on stackoverflow for some. And I did find some people talking about it, like

Glassfisch MySQL ping ERROR (no answer by anybody), or

Struggling to create MySQL Connection Pool on Glassfish (tried that solution, i.e. putting the SQL driver one level up in ..\GlassFish3\GlassFish\domains\domain1\lib\, but this creates other errors, even after restarting the Glassfish server), or

GlassFish not loading connector
(even tried this solution, no succes).

Can somebody help me solve this problem? Many thanks in advance!

With kind regards,

Heinz

Best Answer

Place the mysql driver in the lib folder of your project. Then do a clean-and-build. It's also helpful to have netbeans communicate directly with your database. This will allow you to view the database structure and the contents of your database right from your IDE. For help integrating MySQL with netbeans, look here: netbeans.org/kb/docs/ide/mysql.html

Related Topic