Checking SQL  null  values

Posted on 2004-11-20
Last Modified: 2010-03-31
  I getting values from database , I m concating these value and passing back in bean,
       If in database value is null I want to Pass "Not specified"  ..
   How can I compare SQL  null..?
I did this ..
String tCityId ="Not specified";
            tCityId             =rs.getString(1);
How to do this?

Question by:Manish
    LVL 13

    Accepted Solution

    String dbValue = rs.getString(8);
    tCityId = (dbValue == null)?"Not specified":dbValue;
    LVL 3

    Expert Comment

    String dbValue = rs.getString(8);
    String tCityId = "";
    if(dbValue == null)
    tCityId = "Not Specified";
    tCityId = dbValue;

    LVL 13

    Expert Comment

    same result as mine but more code
    LVL 92

    Assisted Solution

    String tCityId = rs.getString(8);
    if (rs.wasNull()) tCityId = "Not Specified";
    LVL 11

    Author Comment

      As null value is string stored in database..
    I did this..
    Any way thanks...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Suggested Solutions

    Title # Comments Views Activity
    Increment alphanumeric sequence 6 55
    array11 challenge 16 40
    json example 39 77
    word0 challenge 3 30
    For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now