Re: Db2dclgn Indicator variables
- From: "Frank Swarbrick" <Frank.Swarbrick@xxxxxxxxxxxxxx>
- Date: Mon, 22 Jan 2007 11:25:25 -0700
LX-i<lxi0007@xxxxxxxxxxxx> 01/21/07 2:50 PM >>>
Frank Swarbrick wrote:one)
I'd also love to see some kind of COBOL support for "null" values. Even
with the proposed COBOL 2008 features (of which ANY LENGTH PREFIXED is
actualI don't think there's anyway way to specify a field (other than an
it!pointer, of course), as having a value of "NULL". But I'd love to see
it,I know that C# has support for this. Never seen any other language with
though.
VB handles nulls, as does Java.
I'm not sure it's quite as elegant as the C# method. Let me give a few
examples. I have a Java JDBC program that reads records from an Oracle
table and inserts them into a DB2 table with the same structure. Here is
some code from it:
resultset =
stmtOracle.executeQuery(SELECT_ORACLE_ICM_POSPAY_ISSUED_CHECKS);
while (resultset.next()) {
handleRow(++cnt, resultset, pstmtDB2);
pstmtDB2.executeUpdate();
if (++cnt2 > 5000) {
conICMDB2.commit();
cnt2 = 0;
}
}
The significant part of it is handleRow() (see below), which gets the
columns from the current row in the Oracle resultset and sets the
corresponding in the DB2 prepared-statement object. With the code for most
of the columns deleted, here's my Java:
void handleRow(int c, ResultSet rs, PreparedStatement ps)
throws SQLException {
int i = 0;
rba = rs.getInt("UNIQRBACNT");
ps.setInt(++i, rba);
lockedUserProfileID = rs.getInt("LOCKED_USER_PROFILE_ID");
if (rs.wasNull())
ps.setNull(++i, Types.INTEGER);
else
ps.setInt(++i, lockedUserProfileID);
}
UNIQRBACNT is a columns defined as NOT NULL, while LOCKED_USER_PROFILE_ID is
nullable. Look at how much extra code is required to handle the nullable
column? In fact, the non-nullable one can simply be:
ps.setInt(++i, rs.getInt("UNIQRBACNT"));
In C# there is a way to declare a field as being "nullable". That is,
instead of say...
int lockedUserProfileID;
You instead say
int? lockedUserProfileID;
Then, and I haven't actually tested it so I may in fact be wrong, I imagine
you would be able to say something like:
lockedUserProfileID = rs.getInt("LOCKED_USER_PROFILE_ID");
ps.setInt(++i, lockedUserProfileID);
without the annoying testing for null.
To be honest, as I write this I am not convinced that this would actually
work. But it certainly would be nice if it did. If I think of it I will
indeed test this at home.
Anyway, check out this website for more info:
http://blogs.msdn.com/ericgu/archive/2004/05/27/143221.aspx
Does Java, in fact, support something like this? I couldn't find anything,
but I am far from expert.
Frank
---
Frank Swarbrick
Senior Developer/Analyst - Mainframe Applications
FirstBank Data Corporation - Lakewood, CO USA
.
- References:
- Db2dclgn Indicator variables
- From: Dan van Ginhoven
- Re: Db2dclgn Indicator variables
- From: Frank Swarbrick
- Re: Db2dclgn Indicator variables
- From: LX-i
- Db2dclgn Indicator variables
- Prev by Date: Re: Db2dclgn Indicator variables
- Next by Date: Re: searching for a cobol job
- Previous by thread: Re: Db2dclgn Indicator variables
- Next by thread: Looking for A Screen Scraper
- Index(es):
Relevant Pages
|