2014-09-30 19 views
1

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的:數據源的驅動程序類名稱缺失

enter image description here

鳥類資源:

enter image description here

成功的ping:

enter image description here

(平確實表明連接屬性是正確的?)

塊小:

<!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中,因此這不是一個完美的解決方案。

+0

還看到:https://netbeans.org/kb/docs/javaee/ecommerce/connect-db.html雖然似乎有點過時,但似乎與上面的教程保持一致。和http://wiki.netbeans.org/UsingJSFAndFaceletsInNetbeans – Thufir 2014-09-30 08:51:23

回答

2

我有一個類似的問題,它基本上是netbeans問題(這就是爲什麼在glassfish管理控制檯中一切似乎都很好)。

爲了解決:
1.添加MySQL連接器的Java-5.1.23-bin.jar爲 「{$ installation_folder} \的NetBeans 8.0.1 \ IDE \模塊\ EXT」
2.重啓netbeans的
現在它應該按預期工作

bug report也有關

+0

我敢肯定,這是正確的,只是因爲我沒有(重複)的問題沒有接受答案.. – Thufir 2016-04-11 04:17:51

1

爲了解決你有同樣的問題,我不得不在你的連接池中添加一個「driverClass」附加屬性(旁邊的「密碼」,「用戶「,」URL「)。 它的值將是「com.mysql.jdbc.Driver」。

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

+1

你可以使代碼很好地顯示通過將它放在一個新行中,將它放在反引號(')之間,選擇它並按下Ctrl-k。你可以[編輯]你的文章來改進格式。 – 2017-07-04 11:01:39

相關問題