• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Separate a ResultSet over multiple TableColums within a ObservableList<String>  RSS feed

 
Ranch Hand
Posts: 47
1
IntelliJ IDE Java Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Expected Behaviour
The handleConnect() should dynamically build a Tables, Cloumns, and Rows within a TabPane. Each cell containing the correct corresponding value.

Current Behavior
The handleConnect() calls upon dbController.queryRows() and somehow the ResultSet data keeps being dumped into each individual cell.




DBController.queryRows()


Controller.handleConnect()


I have tried many different combinations of code to get this to work. In fact, before I began refactoring this project to separate the database code into DBController, it worked correctly. I'm stuck, can anyone please help?
Full project code can be found at it's github repository.
 
Master Rancher
Posts: 1162
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if I understand the question correct, but you want to split the first cell over the row, each cell only containing one value?
You have a data object that you retrieve from the db right?
I never did it with jdbc but I guess the way to do is the same
The way to go would be something like:
 
Eric Arnold
Ranch Hand
Posts: 47
1
IntelliJ IDE Java Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Daniel Demesmaecker You have the right idea, as far as what I'm trying to achieve, but you missed the part about it being dynamic. The table columns are not hard coded, this application first retrieves a List<String> `tableNames` (80) , which it uses to generate the Tab's for each table in the database. It then retrieves a Map<String, String> `columns` (Controller.java line 87) which is iterated over, creating the columns with the corresponding names / types. Finally (and this is where the issue lies) I'm thinking it should create an ObservableList<ObservableList> `rows` (Controller.java line 109) consisting of the cell data for the entire table. And to a degree it is working, it is actually setting the correct values, just, the entire ResultSet row is being saved in each cell, instead of it being distributed according to the number of columns (DBController.java line 74).

Controller.java


DBController.java
 
Daniel Demesmaecker
Master Rancher
Posts: 1162
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're making it way more complicated then it has to be... How your columns are created dosn't mather, my approach will still work
 
Eric Arnold
Ranch Hand
Posts: 47
1
IntelliJ IDE Java Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Well, I've trying different combinations of your solution all night, nothing is working. Any other ideas?
 
Eric Arnold
Ranch Hand
Posts: 47
1
IntelliJ IDE Java Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is how it was handled before, and this works correctly.

 
Sheriff
Posts: 5745
148
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the first snippet of code you posted, I see
So you add an observable list of observable lists to the table, and it it shows an observable list in each column, just like you told it to.  As you may know, tables like to work with an observable list of objects.  Getting a Table to work with disparate data is difficult.  I believe you can do this with a Map of Maps. Give me a second to russle up some code.  (It may be more than a second.)
 
Knute Snortum
Sheriff
Posts: 5745
148
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, here is a basic app using an ObservableList of Maps to model the data of a Table.
I leave it to you to adapt this to a truly dynamic table, but I think this is the way.
 
Eric Arnold
Ranch Hand
Posts: 47
1
IntelliJ IDE Java Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is so frustrating! I can't understand why the same code works in one method, but wont in the other.......... I've been trying to refactor this for over 2 weeks now.
connect() and handleConnect() are essentially the same, only difference being how the columns are created, either by if/else if in connect() or a switch in handleConnect() I've added debugging code in both classes, it should work, why wont it work!?!?
Controller.java


DBController.java
 
Daniel Demesmaecker
Master Rancher
Posts: 1162
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I worked out an example, it's still a bit rough edged, but it should at least give you an indea on how to tackle it.
For the example I used an table of containing amfibia from a hangmangame I once created.
The class that handles the connection to the db:


As you can see the connection is private since the user don't need to know about it. Now that query string is hardcoded but you could pass it as a parameter to the method, so you could execute different queries.
Since you had this part down, I won't explain it any further. Next i created an object class to put the values of my resultset in. In my case Word, it's a simple class with a constructor that takes the parameters for all variables and getters and setters.
My default .fxmlfile (the one that's being opened in your startmethod) contains an anchorpane and an empty Tableview, which I reference in my controller.

My controller:

I think you mentioned you're getting nullpointers? I had that problem first too. I suspect it has to do with the try's, somehow the controller has dificulties with that, that's why I seperated everything handling the exceptions there and that seemed to work.

All that results in:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!