dimanche 27 mars 2016

JavaFX Sqlite get ID from selected ListView Element

I have a ListView which is filled with artwork names (from SQLite database), these are strings and the names are not primary keys (not unique). Of course each artwork has its own ID (primary key).

What I do, I select one artwork from this list and pass it as a string argument to a button, which creates additional informations (that is not neccessary for this question).

But I select the name, now I need to get the ID from this selected artwork as foreign key.

Of course I can create a select query like this:

"select * from Artwork where Name = ?";

and then get the ID from the artwork with this name, but as I said before, there can be multiple artworks with the same name, so this is not good.

The Plan B which I have is to display in the ListView also the IDs of the the artworks, then If you select one artwork, you could slice the String at " " and take work with the list argument which contains the ID.

But that does not feel right.

Thanks! I hope you understood what I need, if not I could provide code, but there is really a lot.

Aucun commentaire:

Enregistrer un commentaire