NetBeans + GlassFish应用程序无法从数据库中查看该表

时间:2014-03-31 18:16:25

标签: jsf java-ee netbeans jdbc glassfish

我的数据库中表的可见性存在问题。 我正在尝试编写一本示例项目来自书籍#34; Java如何编程第9版"从JavaServer Faces一章开始,我已经完成了所有操作而没有任何错误,但是我的Web应用程序没有看到我的表。

servicetab in netbeans http://www.iv.pl/images/98495825713921260154.png

如你所见,我有一张桌子应该是(名字为ADRESY)。 这是我的SQL查询代码。

public ResultSet getAddresses() throws SQLException{
    if(dataSource == null)
        throw new SQLException("Unable to obtain DataSource");

    Connection connection = dataSource.getConnection();
    if(connection == null)
        throw new SQLException("Unable to connect to DataSource");

    try{
        PreparedStatement getAddresses = connection.prepareStatement(
        "SELECT FIRSTNAME, LASTNAME, STREET, CITY, STATE, ZIP " +
                "FROM ADRESY ORDER BY LASTNAME, FIRSTNAME");
        CachedRowSet rowSet = new com.sun.rowset.CachedRowSetImpl();
        rowSet.populate(getAddresses.executeQuery());
        return rowSet;
    }finally{
        connection.close();
    }
}

在此之前我有注释:

@Resource ( name="jdbc/addressbook" )
DataSource dataSource;

没有错误,但是当我运行使用此语句的页面时,我遇到错误:

  

发生错误:

     

表/视图' ADRESY'不存在。

屏幕资源: resources glassfish http://www.iv.pl/images/77706421595933269755.png

并按照要求(不确定这是否是您想要的): resource jndi name http://www.iv.pl/images/79884566162836729459.png

我的web.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
        http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
    <resource-ref>
        <res-ref-name>jdbc/addressbook</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
</web-app>

之前我没有<resource-ref>标签,我刚才添加了它,但它仍然没有用。我想我没有glassfish-resources.xml文件。

我检查了这个驱动程序,然后是下一个屏幕截图: connection pool driver http://www.iv.pl/images/78467121145061967972.png

驱动程序类名为空但在创建连接池时,我选择Java DB作为驱动程序供应商。我不知道它是否应该是这样......

1 个答案:

答案 0 :(得分:2)

  

我认为我没有glassfish-resources.xml文件。

http://www.oracle.com/technetwork/articles/java/pongegf-1517943.html

  

应用程序范围的资源被声明为被调用文件的一部分   与GlassFish resources.xml中。在WAR部署的情况下,文件是   放在WEB-INF / glassfish-resources中。

您可能还想尝试ping您的游泳池。您在“EDIT JDBC连接池”屏幕的左上角有一个“ping”按钮。查看截图。

相关问题