如何设置glassfish-resource.xml和web.xml?

 手机用户2502891053 发布于 2023-01-30 17:04

我有一些疑难解答,我真的不明白为什么会这样.我正在制作简单的网络服务,试图转到数据库并获取1条记录.

我通过NetBeans向导添加新的服务器资源.NB为它创建了新的资源和连接池.看起来像这样:




  
    
  
  
    
    
    
  

我在Web.xml中进行了更改.像这样:

    


    
        
            30
        
    
    
      DB Connection Pool
      jdbc/testdb
      javax.sql.DataSource
      Container
      Shareable
   


但是在测试玻璃鱼没有把我连接到这个基地.它使用defaultPool.这是日志:

WARNING:   RAR5038:Unexpected exception while creating resource for pool DerbyPool. Exception : javax.resource.spi.ResourceAllocationException: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.
WARNING:   RAR5117 : Failed to obtain/create connection from connection pool [ DerbyPool ]. Reason : com.sun.appserv.connectors.internal.api.PoolingException: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.
WARNING:   RAR5114 : Error allocating connection : [Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.]
SEVERE:   java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.

我究竟做错了什么?

1 个回答
  • 问题是资源类型不正确.您将资源列为javax.sql.DataSource.但是,您实际上正在使用javax.sql.ConnectionPoolDataSource

    <resource-ref>
       <description>DB Connection Pool</description>
       <res-ref-name>jdbc/testdb</res-ref-name>
       <res-type>javax.sql.ConnectionPoolDataSource</res-type>
       <res-auth>Container</res-auth>
       <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
    

    尝试在Glassfish服务器和SQLite DB之间建立数据库连接时遇到了类似的问题.我认为问题是图书馆不支持它,但改变<res-type>解决了问题.

    归因于这个问题的一件大事是我试图通过NetBeans提供的工具添加此资源.这一切都很好,但是每当你尝试Resource Reference在你的web.xml文件中添加一个,你只会在下拉列表中看到有限的选择池,这让我相信这些是唯一有效的选项.

    但是,您可以手动键入类到下拉列表的文本框或者你可以去Sourceweb.xml中的观点和手工输入类有.

    可用的Netbeans资源参考

    此外,如果您使用sun-resources.xml文件自动将资源添加到服务器,我的文件在最终工作时看起来像这样(为编辑的属性添加了省略号):

    <resources>
       <jdbc-resource 
          enabled="true" 
          jndi-name="jdbc/rpg" 
          object-type="user" 
          pool-name="RpgPool">
          <description>Description</description>
       </jdbc-resource>
       <jdbc-connection-pool 
          ...
          datasource-classname="org.sqlite.SQLiteConnectionPoolDataSource" 
          ...
          res-type="javax.sql.ConnectionPoolDataSource" 
          wrap-jdbc-objects="false">
          <description>Description</description>
          <property 
             name="URL" 
             value="jdbc:sqlite:C:/some/where/out/there"/>
       </jdbc-connection-pool>
    </resources>
    

    2023-01-30 17:05 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有