Check if user in a database is banned JDBC

Posted by user2297666 on Stack Overflow See other posts from Stack Overflow or by user2297666
Published on 2013-06-24T13:28:29Z Indexed on 2013/06/24 16:21 UTC
Read the original article Hit count: 82

Filed under:
|
|

Using an oracle database, I need to perform a check to see if a user in my 'users' table is banned or not. The user is banned if his column 'banned' has a value of '1', '0' if he is not.

I have the following working code here:

public boolean banUser(String username)
    {//TODO check if user is banned already
        try 
        {
            pstmnt = conn.prepareStatement("UPDATE users SET banned = 1 WHERE username = ?");
            pstmnt.setString(1, username);
            pstmnt.execute();
            logger.info("Banned User : " + username);
            return true;
        } catch ( SQLException e ) { e.getMessage(); }
        return false;
    }

I'm not sure how to perform an if statement on top of a prepared statement. Any ideas?

© Stack Overflow or respective owner

Related posts about java

Related posts about Oracle