0

What is the easiest way to join two tables to provide the data for a jTable and make use of the Netbeans gui builder code? Netbeans gui builder makes setting up a jTable for a single database table a simple case of making selections that are presented--quick and easy. It would seem some hacking of the generated code, or simple extension, to join two tables (or even make a more complex query) would be possible. There are web posts that show different ways of setting up a jTable, but they don't make use of the gui builder. If I had more experience with java maybe I would see how to translate their examples for use with the gui builder generated code, but I am not there yet.

Added item: For the current program effort the database does not need to be updated, i.e. read-only.

  • 1
    FWIW Here's one recommendation of steering away from GUI builders if you do not yet know how to build a UI manually. Reason being: they auto generate code which can sometimes be a nightmare to understand, customize, and debug. – copeg Sep 23 '16 at 00:32
  • I agree it is best to understand the level below that one is using, e.g. decoding core dumps of asm (in the early 1960s) or emitted code from C source, but to put it nicely it is “tedious” to code in the lower level when the higher level suffices. Idea: Make an empty database table that gui builder uses, then upon startup do the sql “inserts” from the tables that are joined to this temporary table. Let the gui builder do all the tedious work. – user3304253 Sep 23 '16 at 03:44
  • 1
    @copeg wasn't talking about decoding byte code but to make your GUI by hand w/o using a GUI builder, for the reasons already explained by him. Let the GUI builder do all the tedious work when you know how to do it yourself, not before – Frakcool Sep 23 '16 at 04:31
  • Thanks for the responses and general advice. When I look at the gui builder generated code I can see what it is doing in general and it looks like there would be several strategies for handling table join queries. I was hoping someone familiar with the Netbeans gui builder would have some specific ideas and directions – user3304253 Sep 25 '16 at 01:19

1 Answers1

0

The following is an almost trivial way to display a table from joined database tables and make use of the gui builder. Basically, use sql queries to generate a temporary table and use the Netbeans gui builder with this table. The following is an example. The first statement deletes the old table. The second creates the new table with the columns from the joined tables. The third is necessary to assign a primary key. The fourth transfers the data into the new table. Netbeans gui builder then handles this table as it would any other.

DROP TABLE T3;

CREATE TABLE T3 AS (SELECT * FROM CANID JOIN PAYLOAD_TYPE ON CANID.CAN_MSG_FMT = PAYLOAD_TYPE.PAYLOAD_TYPE_NAME) WITH NO DATA;

ALTER TABLE T3 ADD PRIMARY KEY (CANID_HEX);

INSERT INTO T3 (SELECT * FROM CANID JOIN PAYLOAD_TYPE ON CANID.CAN_MSG_FMT = PAYLOAD_TYPE.PAYLOAD_TYPE_NAME);