First, execute a SELECT statement, something like:
select un from login where un=<given username> and pw = <given password>
If this returns >= 1 rows, this means such a user
exists so proceed with your UPDATE statement.
If the SELECT statement returns 0 rows, no such user exists.
See some simple tutorial with samples on the web.
For example, this one looks OK.
http://www.tutorialspoint.com/jdbc/jdbc-select-records.htm
See STEP 5 there.