Code example for SQLException

Methods: getErrorCode

0
            ps.setString(2, pass);
 
            ps.execute();
            ps.close();
        } catch (SQLException ex) {
            if (ex.getErrorCode() == 1) {
                System.out.println("ERROR: Add Account: Username already exists.");
            } else { 
                Logger.getLogger(DBManager.class.getName()).log(Level.SEVERE, null, ex);
            } 
            return false; 
        } 
 
        System.out.println("Added new account   " + username + ":" + pass);
 
        return true; 
 
    } 
 
    /** 
     * Altera a password da conta indicada.