Tom
Tom

Reputation: 2349

Java - Retrieving data from database based on user logged in

If say, I logged in to my own website, I want to return data that I have submitted to the database. Problem is, how do I query the database to return only my data?

I understand that the query would like this using PreparedStatement:

select * from TableName where Username = ?

I want to add the parameter depending on who is logged in, not just 1 person. Sorry I know I might not explained it well, please ask if not clear.

Edit: If I login, I expect the viewreports.jsp to show the reports I have submitted

Upvotes: 0

Views: 2610

Answers (1)

Goran Jovic
Goran Jovic

Reputation: 9508

The only thing you can do is to:

  • Add a column to all your database tables with an id or a name of whoever submitted it

  • Alter your insert queries to write the name or id of logged in user

  • Alter queries for all such tables to have one additional condition, which is if the logged in user matches the value from that column.

Upvotes: 1

Related Questions