0
votes

I've been trying to create a MySQL connection pool in GlassFish using but it keeps showing this message:

Connection could not be allocated because: Access denied for user ''@'localhost' (using password: NO)

this is the connection URL for the glassfish-resources.xml:

<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="table" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="connectionPool" non-transactional-connections="true" ping="true" pool-resize-quantity="2" pooling="true" res-type="javax.sql.ConnectionPoolDataSource" statement-cache-size="0" statement-leak-reclaim="false" statement-leak-timeout-in-seconds="0" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="true">
<property name="URL" value="jdbc:mysql://localhost:3306/testDB"/>
<property name="User" value="root"/>
<property name="Password" value="mypasswordgoeshere"/>

I read many articles before posting this question, many of them recommend editing the mysql.users table and adding a password to root, but I'm using the version 5.7.7 of MySQL where the 'password' column was removed.

I'm also using NetBeans 8.0.2 to create the connection pool, and GlassFish 4.1, I'm working on a Maven Project with JSF2.0 and PrimeFaces, the server is up and running correctly.

Another strange thing is that GlassFish shows that my project has been deployed already, but it says the page couldn't be found.

2

2 Answers

0
votes

Your glassfish-resources.xml looks wrong to me. You don't have an end tag for root <jdb-connection-pool> and also some properties are wrong, Please try the following:

    <jdbc-connection-pool name="jdbc/test-pool" res-type="javax.sql.DataSource"
    datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
    pool-resize-quantity="1" max-pool-size="5" steady-pool-size="0"
    statement-timeout-in-seconds="60" >
       <property name="serverName" value="localhost" />
       <property name="portNumber" value="3306" />
       <property name="dataBaseName" value="testDB" />
       <property name="User" value="root" />
       <property name="Password" value="mypasswordgoeshere" />
       <property name="connectionAttributes" value=";create=true" />
     </jdbc-connection-pool>
<jdbc-resource jndi-name="testDB" pool-name="jdbc/test-pool" enabled="true" />

After this you could use JNDI lookup using your jndi-name to create a java.sql.Connection.

0
votes

Okay, I fixed part of the problem by doing the following steps, but I'm not sure exactly which one did the trick.

  1. Include the latest mysql-connector-javaX.X.XX-bin.jar in here: %glassfishinstallfolder%\glassfish\lib
  2. Created the resource pool again from the glassfish' domain admin console (localhost:4848/) in Resources -> JDBC -> JDBC Connection Pools using java.sql.Driver as Resource Type instead of Javax.sql.ConnectionPoolDataSource.
  3. Added 3 Additional properties to the Connection Pool I created; password, user, and URL. These all are about the server, the url I used was jdbc:mysql://localhost:3306/testDB
  4. Created a new JDBC resource in Resources -> JDBC -> JDBC Resources called JNDI_testDB using the pool I created in the previous step.
  5. Added the tags < jta-data-source>JNDI_testDB< /jta-data-source> and < property name="eclipselink.target-database" value="MySQL57"/ > to my persistence.xml file.

I still have other problems, my project is still not showing in localhost:8080/test but I'll leave that for another question.