Results 1 to 6 of 6
  1. #1
    Dawesome is offline Member
    Join Date
    May 2012
    Posts
    7
    Rep Power
    0

    Default 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.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,925
    Rep Power
    19

    Default Re: History function in Java (Eclipse) by callin MySQL database

    What does your history table look like?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Dawesome is offline Member
    Join Date
    May 2012
    Posts
    7
    Rep Power
    0

    Default 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)
    Last edited by Dawesome; 05-16-2012 at 09:46 AM.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,925
    Rep Power
    19

    Default 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.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Dawesome is offline Member
    Join Date
    May 2012
    Posts
    7
    Rep Power
    0

    Default 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 :) ?

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,925
    Rep Power
    19

    Default 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.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 5
    Last Post: 09-16-2011, 06:58 AM
  2. Replies: 15
    Last Post: 04-15-2009, 01:51 AM
  3. How to access MySQL Database in Eclipse 3.2
    By nijava in forum Eclipse
    Replies: 2
    Last Post: 12-12-2008, 03:04 PM
  4. Replies: 2
    Last Post: 06-12-2008, 07:09 AM
  5. MySQL Database and Java
    By shaggymac in forum Advanced Java
    Replies: 1
    Last Post: 05-01-2008, 09:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •