从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确实表明连接属性是正确的?)
小面:
<!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连接到数据库。
编辑字段的选项显示为灰色。
-------------------------------------------- edit-- -------------------------------
通过右键单击企业应用程序并选择新的 - &gt; Netbeans做了一些魔术并创建了连接(我认为) glassfish&gt; jdbc连接池。
太阳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
实际上并不是玻璃鱼,这使得这不是一个完美的解决方案。
答案 0 :(得分:2)
我有一个类似的问题,它基本上是netbeans问题(这就是为什么在glassfish管理控制台中一切似乎都很好)。
解决:
1.将mysql-connector-java-5.1.23-bin.jar添加到“{$ installation_folder} \ NetBeans 8.0.1 \ ide \ modules \ ext”
2.重启netbeans
现在它应该按预期工作
此bug report也是相关的
答案 1 :(得分:1)
要解决您遇到的同样问题,我必须在连接池中添加“driverClass”附加属性(“password”,“user”,“URL”旁边)。 它的值将是“com.mysql.jdbc.Driver”。