Results 1 to 4 of 4
  1. #1
    emp
    emp is offline Member
    Join Date
    Apr 2009
    Posts
    5
    Rep Power
    0

    Default accessing variables

    I have some code thats been driving me insane. I need to access some variables but cannot as they appear to not be in scope. Code as follows -

    while (rs.next()) {
    String result = rs.getString(1);
    String r1 = new String (result);
    if (r1.equalsIgnoreCase(search)){
    String var_nonunique = new String ("true");}
    }

    if (var_nonunique.equals("true")){
    etc.....

    The issue is that I cant access the var_nonunique at the bottom as it cannot be resolved.

    Any thoughts on how I can access this?

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    Just define the variable out of the while loop....

    Java Code:
    [COLOR="Blue"][B]String var_nonunique;[/B][/COLOR]
    while (rs.next()) {
    String result = rs.getString(1);
    String r1 = new String (result);
    if (r1.equalsIgnoreCase(search)){
    [COLOR="blue"][B]var_nonunique [/B][/COLOR]= new String ("true");}
    }
    
    if (var_nonunique.equals("true")){
    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    emp
    emp is offline Member
    Join Date
    Apr 2009
    Posts
    5
    Rep Power
    0

    Default

    Thanks for that. I'd actually just realised i hadnt done that myself and now the code works.

  4. #4
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Great...

    Glad it worked ...

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. accessing instance variables from static methods
    By ravian in forum New To Java
    Replies: 7
    Last Post: 03-01-2009, 10:09 PM
  2. Accessing USB
    By FieryProphet in forum Networking
    Replies: 3
    Last Post: 12-13-2008, 05:29 AM
  3. Accessing file
    By Doctor Cactus in forum New To Java
    Replies: 1
    Last Post: 10-24-2008, 07:31 PM
  4. accessing cddrive
    By milinkp in forum AWT / Swing
    Replies: 2
    Last Post: 02-06-2008, 08:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •