Thufir
Thufir

Reputation: 8497

the name of the driver class for the datasource is missing

From How to set up a JDBC Connection Pool on Glassfish I would like to connect MyQueue to the Birds JDBC resource in Glassfish. I'm getting an error similar to: The name of the driver class for the datasource is missing; the only difference being that I'm using MySQl instead of PostgreSql:

enter image description here

birds resource:

enter image description here

successful ping:

enter image description here

(the ping does indicate that the connection properties are correct?)

facelets:

<!DOCTYPE    html  PUBLIC "-//W3C//DTD XHTML 1.0  Transitional//EN"  
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head></h:head>
    <h:body>
        This and everything before will be ignored
        <ui:composition template="template.xhtml">
            <ui:define name="navigation">
                <ui:include src="menu.xhtml"/>
            </ui:define>
            <ui:define name="main">
                <h1>bird</h1>
                #{myQueue.next}
            </ui:define>
        </ui:composition>
        This and everything after will be ignored
    </h:body>
</html>

and the bean:

package dur;

import java.io.Serializable;
import java.util.logging.Logger;
import javax.inject.Named;
import javax.ejb.Singleton;
import javax.enterprise.context.ApplicationScoped;
//import javax.inject.Singleton;

@Named
@ApplicationScoped
@Singleton
public class MyQueue implements Serializable {

    private static final long serialVersionUID = 403250971215465050L;
    private final Logger log = Logger.getLogger(MyQueue.class.getName());
    private int next = 1;

    public MyQueue() {
    }

    public int getNext() {
        log.info("next\t" + next);
        return next++;
    }
}

The bean and facelet are functioning correctly, I just want to connect MyQueue to the database. I would like to use JPA to connect to the database.

The option to edit the field is grayed out.

--------------------------------------------edit---------------------------------

Netbeans did some magic and created the connection (I think) by right clicking the enterprise app and select new -> glassfish > jdbc connection pool.

sun-resources.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Resource Definitions //EN" "http://www.sun.com/software/appserver/dtds/sun-resources_1_3.dtd">
<resources>
  <jdbc-resource enabled="true" jndi-name="jdbc/birdsPool" object-type="user" pool-name="birdsPool">
    <description/>
  </jdbc-resource>
  <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="auto-commit" 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="birdsPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.ConnectionPoolDataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
    <property name="URL" value="jdbc:mysql://localhost:3306/legacy?zeroDateTimeBehavior=convertToNull"/>
    <property name="User" value="user"/>
    <property name="Password" value="gtjropjre"/>
  </jdbc-connection-pool>
</resources>

persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="EnterpriseBirdsJPA-warPU" transaction-type="JTA">
    <jta-data-source>jdbc/birdsPool</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties/>
  </persistence-unit>
</persistence>

I'm a bit uneasy with sun-resources.xml and would prefer to see that configuration directly on glassfish. I'm not exactly sure that this will work, but it allowed netbeans to then create an entity class from this connection, so that seems like progress. Again, though, that sun-resources.xml isn't actually in glassfish makes this a less than perfect solution.

Upvotes: 1

Views: 3298

Answers (2)

Soapr
Soapr

Reputation: 91

To solve the same issue you had, I had to add a "driverClass" additional properties in your connection pool (beside "password", "user", "URL"). Its value would be "com.mysql.jdbc.Driver".

Source : http://www.blogarama.com/programming-blogs/194794-wings-hermes-berins-infosec-blog/259237-glassfish-netbeans-name-driver-class-for-datasource-missing

Upvotes: 1

Ahmad Abdelghany
Ahmad Abdelghany

Reputation: 13238

I had a similar problem, it is basically netbeans problem (that is why everything seems to be fine in the glassfish admin console).

To solve:
1. add mysql-connector-java-5.1.23-bin.jar to "{$installation_folder}\NetBeans 8.0.1\ide\modules\ext"
2. restart netbeans
now it should work as expected

this bug report is also relevant

Upvotes: 2

Related Questions