Darc
Darc

Reputation: 883

Displaying data from linked tables in netbeans JTable

I have been writing in java for a few months now and have just started using netbeans. I have spent all day today trying to work out how to connect to an SQL database and display data from 2 tables (ie display the data from from a select statement with an inner join) in a JTable. I have tried using JPQL with the following statment SELECT j, cust.name FROM Job j JOIN j.jobnumber cust where the job table has a field called customer that references id in the customer table. This throws the exception:

Caused by: Exception [TOPLINK-8029] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.EJBQLException Exception Description: Error compiling the query [SELECT j, cust.name FROM Job j JOIN j.jobnumber cust], line 1, column 11: invalid navigation expression [cust.name], cannot navigate expression [cust] of type [java.lang.Integer] inside a query. at oracle.toplink.essentials.exceptions.EJBQLException.invalidNavigation(EJBQLException.java:430)

What am i doing wrong? Can anyone point me to some examples of how to make a linked table java application? I am still in the very early stages of development so a complete change is not out of the question if using a mysql database isnt the best way to go about things thanks

Upvotes: 0

Views: 2064

Answers (2)

Darc
Darc

Reputation: 883

I found that if i deleted the clases it generated for me (for my tables) and recreated them all at once it picked up on the relationship between them and made it in code foe me. I could then use SELECT j FROM Job j and access every thing i needed. I was able to get help from here if anyone else is in need of help http://netbeans.org/kb/67/java/gui-db-custom.html

Upvotes: 0

BillRobertson42
BillRobertson42

Reputation: 12883

This isn't really a netbeans issue, its a Toplink/JPA issue. Since you're getting an EJBQLException, have you looked for EJBQL examples? I don't really know it, so I can't help you, but that is where I would start.

As an alternative, since you've just started learning Java, you might want to try something with less baggage, like straight JDBC.

Also, if you stick with a JPA answer for now, or switch back to it in the future, you should consider EclipseLink. It has basically superseded Toplink, which had become buggy and unloved.

Upvotes: 1

Related Questions