History function in Java (Eclipse) by callin MySQL database
Hey there :)
So im making an ATM-machine as a project this year.
The idea is that you can log-in to the machine and withdraw/deposit money.
The users will be connected to a MySQL database (this is being working on) and we want to build a History function that can show a users last transactions by calling the MySQL database.
I have been trying to work this out but i am kinda stuck. I was hoping some of you guys would help me out a bit :)
Regards Dawesome.
Re: History function in Java (Eclipse) by callin MySQL database
What does your history table look like?
Re: History function in Java (Eclipse) by callin MySQL database
The history table will be something like this:
time - Userid - Username - Balance - Withdraw - Deposit
Something like that. So i want to be able to call the withdraw and deposit from the SqlDatabase in Java and show it in fx a JLapel.
Hope it makes sense :) (sry for the late reply)
Re: History function in Java (Eclipse) by callin MySQL database
Presumably you know the userid, so do a 'SELECT <fields> FROM <history table name> WHERE userid = ?'.
Iterate over the ResultSet and convert each line into an object of a suitable class and supply that to the front end.
I'm really not sure where you are having the problem with this.
Re: History function in Java (Eclipse) by callin MySQL database
I understand the logic behind it. But im a beginner at java. I know the select. But how would you write it in java so that it would take the information and show it in a JTabel :) ?
Re: History function in Java (Eclipse) by callin MySQL database
Do it a bit at a time.
Create a History class that holds the data you want (or even simply models the table).
Create a DAO (Data Access Object) that has methods for interacting with that table in the database, in your case a single method for the time being that accepts a user id and returns a List<History>.
Write that method so it retrieves the rows from the database for the given user id and builds a List of History objects to return.
From the other end, create a TableModel that uses takes a List<History> and allows the owning JTable to display them.
You never do these things all in one go.