473,394 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

NVL IsNull equivilent in Java? (Null handling)

Hello all,
I was wondering if there a method/function etc that is simular to
Oracle's Nvl function. The funtion checks a parameter and if it is
null then is will output a given alternative. i.e. nvl(parameter1,
value1) if parameter1 is null then send value1.
I have a servlet with the following snippet of code that I'd like to
streamline as this is one of many checks to be made...ideas?
if(request.getParameter("idcol")!= null)
{
int idcol = Integer.parseInt(request.getParameter("idcol").tri m());
}else{
int idcol = 0;
}
Jul 17 '05 #1
2 80207
Di***********@hotmail.com (DiggidyMack69) wrote in message news:<c8*************************@posting.google.c om>...
Hello all,
I was wondering if there a method/function etc that is simular to
Oracle's Nvl function. The funtion checks a parameter and if it is
null then is will output a given alternative. i.e. nvl(parameter1,
value1) if parameter1 is null then send value1.


There's nothing directly equivalent to that function. However, there are
two alternatives:

(1) Using the tertiary operator (also used in C/C++)

The expression: <condition> ? <a> : <b>
evaluates to <a> if <condition> is true or <b> if condition is
false.

Your snippet could be rewritten as:
int idcol = (request.getParameter("idcol")!= null) ?
Integer.parseInt(request.getParameter("idcol").tri m()) : 0;

(2) Writing the function you're looking for yourself and putting it in
some static function in a utility class.

Steve
Jul 17 '05 #2
sl@digilevel.com (Steve Lieberman) wrote in message news:<be**************************@posting.google. com>...
Di***********@hotmail.com (DiggidyMack69) wrote in message news:<c8*************************@posting.google.c om>...
Hello all,
I was wondering if there a method/function etc that is simular to
Oracle's Nvl function. The funtion checks a parameter and if it is
null then is will output a given alternative. i.e. nvl(parameter1,
value1) if parameter1 is null then send value1.


There's nothing directly equivalent to that function. However, there are
two alternatives:

(1) Using the tertiary operator (also used in C/C++)

The expression: <condition> ? <a> : <b>
evaluates to <a> if <condition> is true or <b> if condition is
false.

Your snippet could be rewritten as:
int idcol = (request.getParameter("idcol")!= null) ?
Integer.parseInt(request.getParameter("idcol").tri m()) : 0;

(2) Writing the function you're looking for yourself and putting it in
some static function in a utility class.

Steve

Much cleaner, thanks!!
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Trev | last post by:
I have two tables, tblMTO and tblIMPORT_MTO. If I import an entire MTO into the import table I want to create a delta from it (i.e. leave only the changed items). I have a view (simplified) ...
3
by: Jan Nielsen | last post by:
Hi I am working with rowfilters in dataviews. I would like to filter for empty fields (= null value in the database) I found this sentence on msdn: **************** To return only those columns...
4
by: Laphan | last post by:
Hi all In my functions I'm using a double-check all the time to trap if a value has nothing in it and my question is do I need this double-check. My check line is: IF IsNull(xxx) OR...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
2
by: Raoul Watson | last post by:
I have used isNull statement for as long as I have used VB.. Recently I am devugging a program and it is very clear that the "IsNull" function sometimes would return a true even when the value is...
6
by: Rhino | last post by:
I'm trying to debug a simple Java UDF written in the DB2General style within Eclipse. I'm getting a java.lang.UnsatisfiedLinkError when I execute the set() method in the UDF. I know that the...
16
by: madeleine | last post by:
Please can someone help me, I think I may go mad with this one: Do While Not IsNull(CDate(FormatDateTime(rst!F1.Value, vbShortDate))) If IsNull(CDate(FormatDateTime(rst!F1.Value, vbShortDate)))...
2
by: Hexman | last post by:
Hello All, In SS EE I have nulls in a column. I want to select and eventually change to a zero (its a smallint column). I've tried selecting 'null', 'dbnull', etc. Then I read about the ISNULL...
4
by: jimm.sander | last post by:
Hello, Problem: Im using isnull() in vbscript to determine if a field returned from a ado object call is in fact null. The problem is when I use isnull in anything other than a response.write()...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.