1

I am trying to run a web application called AddressBook (JSF with Facelets) in the NetBeans 8.0.2 IDE with GlassFish 4.1 that accesses a relational database via the following code in the managed bean:

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

When I run the application I get the following error in the browser:

java.sql.SQLSyntaxErrorException: Table/View 'ADDRESSES' does not exist
    at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
    at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
    at org.apache.derby.client.am.Connection.prepareStatement(Unknown Source)
    at com.sun.gjc.spi.base.ConnectionHolder.prepareStatement(ConnectionHolder.java:586)
    at com.sun.gjc.spi.jdbc40.ConnectionWrapper40.prepareCachedStatement(ConnectionWrapper40.java:255)
    at com.sun.gjc.spi.jdbc40.ConnectionWrapper40.prepareCachedStatement(ConnectionWrapper40.java:52)
    at com.sun.gjc.spi.ManagedConnectionImpl.prepareCachedStatement(ManagedConnectionImpl.java:992)
    at com.sun.gjc.spi.jdbc40.ConnectionWrapper40.prepareStatement(ConnectionWrapper40.java:173)
    at addressbook.AddressBean.getAddresses(AddressBean.java:157)

AddressBean.java line 157 is:

PreparedStatement getAddresses = connection.prepareStatement(
            "SELECT FIRSTNAME, LASTNAME, STREET, CITY, STATE, ZIP " +
            "FROM ADDRESSES ORDER BY LASTNAME, FIRSTNAME" );

The addressbook database which contains the ADDRESSES table is created via the following steps:

  1. Create Connection Pool

    1. Right click on GlassFish server and select View Domain Admin Console
    2. In the GlassFish web page in Common Tasks on the left column click on
    3. JDBC Connection Pools
    4. Clicked the New Button and added the following entries:
      • AddressBookPool for the Name
      • javax.sql.DataSource for Resource Type
      • JavaDB for the Database Vendor
    5. Click Next and scroll to Additional Properties and set the following fields:
      • Attributes: ;create=true
      • DatabaseName: addressbook
      • Password: APP
      • Click Finish
  2. Create Data Source Name

    1. In the GlassFish web page in Common Tasks on the left column click on
      JDBC Resources
    2. Click the New Button and specify JDBC/addressbook as the JNDI name
    3. Select AddressBookPool as the Pool name

When I return to the NetBeans Services tab, addressbook has been created under Java DB.

I successfully connect to the database: jdbc:derby://localhost:1527/addressbook [APP on APP] and make APP the default schema

I open a file in NetBeans: addressbook.sql which contains SQL to populate addressbook. I run it on the above connection and ADDRESSES table is created and I am able to view the data.

The AddressBook properties has Java DB Driver as a library.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
jisteinberg
  • 71
  • 1
  • 3
  • 10
  • 1
    `java.sql.SQLSyntaxErrorException: Table/View 'ADDRESSES' does not exist`. The question is purely only related to basic JDBC. There is nothing about JSF, GlassFish and NetBeans. – Tiny Mar 21 '15 at 16:12
  • 1
    Check these common reasons for "table does not exist" in Derby: http://stackoverflow.com/questions/22996818/is-it-necessary-to-create-tables-each-time-you-connect-the-derby-database/23051822#23051822 – Bryan Pendleton Mar 22 '15 at 19:14

1 Answers1

2

Make sure that your web.xml file (in Configuration Files folder) has the resource reference. Example:

    <resource-ref>
        <res-ref-name>jdbc/db1</res-ref-name>
        <res-type>javax.sql.ConnectionPoolDataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>

Where db1 is your jdbc resource name. Also ensure that the value has the correct resource type, a connection pool data source in the example.

Stack Underflow
  • 2,363
  • 2
  • 26
  • 51