• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Table/View Does Not Exist Error for Web Application in NetBeans

 
Jon Steinberg
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am running a web application in the NetBeans 8.0.2 IDE with Glassfish 4.1 that accesses a relational database via the following code:

@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 is comprised of a single table ADDRESSES is created via the following steps:

1) Create Connection Pool
a) Right click on Glassfish server and select View Domain Admin Console
b) In the Glassfish web page in Common Tasks on the left column click on JDBC Connection Pools
c) Clicked the New Button and added the following entries:
AddressBookPool for the Name
javax.sql.DataSource for Resource Type
JavaDB for the Database Vendor
d) Click Next and scroll to Additional Properties and specify the following:
Connection Attributes: ;create=true
DatabaseName: addressbook
Password: APP
Click Finish
2) Create Data Source Name
a) In the Glassfish web page in Common Tasks on the left column click on JDBC Resources
b) Click the New Button and specify jdbc/addressbook as the JNDI Name
c) Select AddressBookPool as the Pool name

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

I connect to the database: jdbc:derby://localhost:1527/addressbook [APP on APP]

I open a file in NetBeans: addressbook.sql which contains SQL to populate addressbook and 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.

 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
APP on APP

I am not sure if I understand this in full detail but looking at some documents, it seems that its a schema .

Try prefixing schema name like below



Regards,
Amit
 
Jon Steinberg
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for feedback. Tried fix but got error Table/View 'APP.ADDRESSES' does not exist. In Services tab I made jdbc:derby://localhost:1527/addressbook [APP on APP] the default schema.
 
Mike P Ryan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Having the same problem Jon. I assume you got this example from Deitel Java for Programmers. Will update if i can get fix
 
Jon Steinberg
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes --- Deitel and Deitel JHTP Edition 9, Section 30.2. The AddressBook project.
 
Mike P Ryan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So i think it has to be security related. If i change the SQL in my code to pull data from one of the system tables in the addressbook database e.g. SYS.SYSTABLES, it will return information correctly. Do you want to try that jon and see if you still get the error when you do that? If so then it proves that you have a valid connection to the database and the issue is elsewhere possibly security
 
Jon Steinberg
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure what you mean by system tables. When I expand jdbc:derby://localhost:1527/addressbook. Under APP schema there is a single table ADDRESSES. No other tables.
 
Mike P Ryan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jon, ive finally got my version to work. I realised after changing my SQL statement to Select * from SYS.SYSTABLES that my ADDRESSES table wasnt being returned. Therefore i knew my application was probably looking at the wrong database. After some investigation i realised that my application was pulling information from the jdbc/__default datasource even though i had used To fix i had to include a file called glassfish-web.xml under WEB-INF. The file looks like

Im not a skilled JSF user but hopefully this works for you if you want to give it a try
 
Jon Steinberg
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike
In NetBeans I noticed that glassfish-web.xml file is under the folder Configuration Files.
I copied it to WEB-INF and the program ran --- so thanks a lot!!!
I wonder what it was about my NetBeans setup made the glassfish-web.xml end up either not where it belonged or not being pointed to properly.
I appreciate your help. I still have one problem, I hope you can help me with.
The address book is displayed with a red error message : Unable to find resource css, style.css
Under my Web Pages/resources/css directory I have cssLayout.css and default.css. My index.html and addentry.xhtml include tag <hutputStylesheet name="style.css" library="css"/>.
What is under your css and how do you get it to include style.css?
Thanks again.
Jon
 
Mike P Ryan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jon,
I just have style.css under resources/css. It contains
 
Jon Steinberg
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike,

An update - I looked at the project in the File tab and saw style.css under web/resource/css so I copied it to folder build/web/resources/css.
I'm still confused why my setup of Netbeans either got things in the wrong directories or the references wrong so they weren't found.

Jon
 
Mike P Ryan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im not sure either jon, im relatively new to netbeans as well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic