MySQL Database and Java
I created a Form using SWING. I have 1 Table in the database.
The table structure is
The purpose of this application is to "Browse" or view data stored in the database.
At the moment, I run an SQL query everytime data is needed.
On my GUI, I have 4 JButtons, 2 JRadioButtons
and all fields are "Editable" but data can not be saved.
So the 4 buttons on my screen are
CLEAR - Clears the contents of all my fields
SEARCH - uses the filled in fields to perform a Dynamic search on the DB
(so if user enters first name as JAMES, it will automatically build a SQL String
SELECT * FROM TABLE WHERE FIRSTNAME = 'JAMES')
NEXT - moves to next record. This runs an SQL Statement
SELECT * FROM TABLE WHERE id=(current+1)
PREVIOUS - moves back a record
SELECT * FROM TABLE WHERE id=(current-1)
The first one is called EXACT. The EXACT one will build the SQL String so it uses the = operator for the where clause (example SELECT * FROM TABLE WHERE FIRSTNAME='JOHN')
The second one is called PARTIAL. The PARTIAL one will build the SQL String so it uses the LIKE operator for the where clause (example SELECT * FROM TABLE WHERE FIRSTNAME LIKE '*JOHN*')
Here is the problem and I think it could be many things that may contibute to the problem
1. When searching for a record, I get the first record. Then when using the NEXT button, it gets the current record + 1. but the next record may not have a sequential id. I may find records with the following id
1, 45, 90, 103
Likewise, the previous button doesn't work.
So the question is how do I figure out what the next record or previous record is when getting data from the DB?
My first instinct would be to check where/how you are setting the value of 'current' and to check whether it is getting reset after clicking the 'Next' and 'Previous' buttons.