Robert Ingmarsson

Ranch Hand
+ Follow
since Jan 12, 2015
Robert likes ...
Netbeans IDE PHP Java
Cows and Likes
Cows
Total received
2
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
11
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Robert Ingmarsson

Best ranchers!

I wish to know how to get the id of the last updated row in java? I know how to insert and update records in a database and retrieve the last inserted id of an insert statement but not how to do the same with an update statement? To update a record i assign a variable with the following command:



If I wan't the last inserted id from an insert statement i would write something like this:



Now how do you retrive the last inserted id after an update statement? My first guess is that you have to use some kind of a query / sub-query-statement for this. But I am still struggling at a very harsh level with my sql so I am very greatful for any kind of response here. Thank you for reading!
Best, Mr. Clapham!

I think I have solved this one out thanks to your reply. I added a CastPerson object as a value in the person_name column of my DefaultTableModel. Here is the method I used for this, it's pretty obvious what is going on in it.



And then i get the id of the selected Person with the following code



Many thanks for the reply.

Wishes,
Robert!
Best, Mr. Lacar!

Sorry for a late reply. You have fully understood my problem. I have a JTable in a JDialog with person_name and character_name as column identifiers. Above the JTable I have a set of JButtons. Among theese buttons there is an "edit person" button. When the user clicks this button another JDialog opens up displaying a form that asks for further information about the selected person. This is why it is so important for me to get the id of the current selected person even if he/she has duplicate entries in the person_name/character_name - JTable. You mentioned the character_name in your latest reply. Could you elaborate? What would the solution be if you put further attention to the character_name-column? Do you have any ideas, sir?

I am trying to use a MVC pattern in my design. But that is my weakest side. I am not so sure about the model part in that procedure.

Best wishes,
Robert!
Hello, again!

I have a table that looks like this



The problem is that I wan't to allow duplicate entries. If I would only allow unique entries then my sql would look something like this



... as suggested earlier.

But I wan't to allow duplicates (person_name column) in my table tbl_castperson and then get the id from the current selected person in that table. This maybe sounds unclear but it something like that I am looking for. Thank you so much for your replies!

/Robert

Best, ranchers!

I am struggling with my sql. Let's say I have a table named "tbl_castperson". This is where I store basic information such as an actors name and charactername in my database. One thing that is bothering me is simply as this - what would the query and the approach be for finding the id of a person with the same person name as others in the forementioned table? I'm working on a JDialog that will present the information about the selected actor and in it there is a JTextField that display the id of the current selected person from the table "tbl_castperson".

What is the procedure for getting the unique id of a person that share the same name with other people in a database? I have looked in on sql-terms like "distinct" and "group by" but that didn't worked out for me. I have a hunch the answer is quite basic and that I am close but everything is at pause for the moment. Please help.

Very kind regards,
Robert!
@Mr. Lacar

Thank you so very, very much for your reply. I must have missed out a lot. I just found out a solution to the "insert person" versus "no titles in the movie-table" dilemma. What if I disable the "Persons" tab in my JTabbedPane of my insert dialog "EditTitleDialog" and let it be in that state until the user have inserted a title in the database?

Best regards,
Robert!
@Mr. Lacar

Thank you so much for your reply. It answered a lot of questions for me. I will apply that design to my project. But still one of my basic issues here is really bothering me. How do you link filmpeople to a movie in a database if there are no titles entered yet? This question is so basic and maybe *dumb* that I am almost ashamed for asking it. Don't even understand my own reasoning here, sorry for that.

Puzzled,
Robert!
 
Hello, again!

I have now created two new tables one called "tbl_filmcast" and the other called, "tbl_filmcrew". They look like this





In the "AddCastDialog" the user enters an actors full name and character name in two textfield. This data is later inserted into the "tbl_castperson" table after which I insert it into the "tbl_filmcast" table with its last inserted id as a foregin key. I then have a "EditCastDialog" that have forms whose inputs are stored in the "tbl_filmcast" table after the user clicks the ok-button. Does this seems like the correct approach to take?

Please forgive the errors in my understanding of this procedure.

Regards,
Robert!    

Best, Mr. Snortum!

I have been struggling with this issue for a long time and I still can't get a grip on it. I understand about many-to-many relationships in a database and joins. It's the design process that is the problem. In my case I have a lot of problem with just trying to figure out how to add filmpeople to their respective tables and link them together if there are no entries in the maintable. What you describe in your reply make perfect sense to me. Could you show me some example tables of the process you are describing?

Best regards,
Robert!    
Best, Mr. Lacar!

Thank you so much for your kind reply. I am currently and struggling reading the article you posted the link to. It seems that I am getting closer to the answer. I have three person tables in my database, "tbl_castperson","tbl_crewperson" and a third, "tbl_filmperson". I am, shortly to say, linking theese together with foreign keys. But for instance, I can't figure out how to link them to a movie if there are no ones yet added in the database? I have a film_id key in my "tbl_filmperson" referencing to the id key in my main table "tbl_mediatitle". Here is what my person tables look like ( I have shorted them down a little bit from their original structure ) :







Something like that. I don't even know if I am on the right track as I mentioned earlier.

I am using the embedded java derby database for this project.

Best regards,
Robert!


Best ranchers!

I am having a real issue with trying to understand how to keep track of movie people in a media manager project of mine. I should mention that - as a rookie - database design is my weaker side when it comes to the whole table processing part. I have so many question concering this subject so I don't really know where to start. I know about foreign keys and how to use them in tables and link them together. But that's how far my knowledge reaches in this aspect of the matter.

I will try to outline my main problem as clearly as possible.

My GUI for this project is quite "simple". I have a main frame with a JTable and a JTabbedPane in a JSplitPane. And then there is a JDialog for inserting a movie. In the movie dialog I have a JTabbedPane with different panels labeled with titles like "Start","Edition","Video","Audio","Personal","Loan","Persons","Episodes" and "Plot". In the persons-tab I have two tables in a JSplitPane, one for cast people and the other is for crew people. The tables are registered to a JPanel. At the top of this JPanel I have three buttons labeled "Add" (person) "Delete" and "Edit". The "Add" button opens up a cast-info / crew-info JDialog with two JTextFields, one for entering the actors name and the other one is for entering the character name. When the user clicks the OK-button I insert the current data in a "tbl_castperson" / "tbl_crewperson" - table depending on which type of movie people the user is inserting. Now I have reached the part where I need help to continue.

Let's go back to the "Persons" - tab in my JDialog. In the "Persons" - tab I have a JButton labeled "Edit". It opens up a "EditPersonDialog" JDialog window. In this JDialog I have multiple textfields and other controls that takes care of information inputs referencing a movie person's full name, original name, birth date, death date, active state, birth place, country, biography and so on. When the user clicks the OK - button in this JDialog then I wan't to insert the current data in a larger table called "tbl_person". My problem is and so is my question - if I am on the right track and how I should proceed? My concern is also how to connect the actors to a title if there is no titles in the database like during a first run of the application? I am sorry if my problem sounds too complicated. But I just need good guidelines on how this is done in an "industrial" process.

Needles to say I am very curious about this matter. Hence I must point out that this post is a question of a basic nature and that I am sorry for not showing any examples of code in it.
But that might change later on.

Thank you so much for your time.

Best regards to everyone,
Robert!                      




I have a side question about event classes in MVC. In a project of mine I have placed my Action objects in a controller class called FrancineController. Is that a valid approach in real life?
I instantiate them in a method called initActions().




That's the place where I keep the language files. What I meant was where do you do the localization part of the mvc sections? The setLanguage(String lang, String country) (custom method) and bundle.getString(String propertyName); Do you do this in the model, controller or the view? I am semi beginner at i18 stuff and doesn't know how this is done in real world applications. So far I do this in a separate class I call Localizer but how do you work with locales in a MVC environment?
In MVC and accordingly to the pattern I made an ascii-drawing of, where would the best place be to hold and work with the ResourceBundle class?
Thanks for the reply!

I see. Ok, so if I am going to use the formula like the one I have presented above, what type of classes should go in each of the above mentioned folders? This is something that I have read on but I wan't to take it from the beginning here. For instance is it correct to place all the gui classes in the controller folder, like my main frame and dialogs and panels?