從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;唯一的區別是,我使用的,而不是PostgreSQL的MySQL的:數據源的驅動程序類名稱缺失
鳥類資源:
成功的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++;
}
}
豆子和facelet裏都工作正常,我只是想MyQueue
連接到數據庫。我想用JPA連接到數據庫。
編輯字段的選項變灰。
-------------------------------------------- edit- --------------------------------
Netbeans做了一些魔術,並創建了連接(我認爲)單擊企業應用程序並選擇新建 - > glassfish> 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
實際上並不在glassfish中,因此這不是一個完美的解決方案。
還看到:https://netbeans.org/kb/docs/javaee/ecommerce/connect-db.html雖然似乎有點過時,但似乎與上面的教程保持一致。和http://wiki.netbeans.org/UsingJSFAndFaceletsInNetbeans – Thufir 2014-09-30 08:51:23