Well you would probably need another db fields as a timedate
`logged_in` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
select id from table where username='blah' and
(unix_timestamp(now())) time1 ,(unix_timestamp(logged_in)+300)
String id = session.getId();
//get current id - compare this to output of your db - if not found then its a new user.
Also when they log out - before doing log out - to store a status in the same table to say logged_out=1;
But they may close the browser so by checking the session id if the same
Learn Java by Examples - How do I count number of online users?
Have a look here for some more guidance on active sessions.