在How to set up a JDBC Connection Pool on Glassfish中,我想将MyQueue连接到Glassfish中的Birds JDBC资源。我得到一个类似于:The name of the driver class for the datasource is missing的错误;唯一的区别是我使用的是MySQl而不是PostgreSql:

鸟类资源:

ping成功:

( ping是否表明连接属性正确?)
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>和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++;
}
}bean和facelet运行正常,我只想将MyQueue连接到数据库。我想使用JPA连接到数据库。
编辑该字段的选项将呈灰色显示。
Netbeans使用了一些魔术,通过右键单击企业应用程序并选择new jdbc glassfish > -> 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>我对sun-resources.xml有点不放心,我更喜欢直接在glassfish上看到这个配置。我不能确切地确定这是否会起作用,但它允许netbeans从这个连接创建一个实体类,所以这似乎是一种进步。尽管如此,sun-resources.xml实际上并不在glassfish中,这使得这不是一个完美的解决方案。
发布于 2014-12-02 11:25:13
我遇到了一个类似的问题,这基本上是netbeans的问题(这就是为什么在glassfish管理控制台中一切正常的原因)。
要解算,请执行以下操作:
连接器将mysql-
现在它应该可以像预期的那样工作了
此bug report也是相关的
发布于 2017-07-04 18:58:26
为了解决同样的问题,我不得不在你的连接池中添加一个"driverClass“属性(在"password","user",”URL“旁边)。它的值将是"com.mysql.jdbc.Driver“。
https://stackoverflow.com/questions/26115638
复制相似问题