Welcome to dbFreaks.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Accessing mainframe DB2 in Java.

 
   Database Help (Home) -> Java RSS
Next:  what is the Difference between MySql and Oracle  
Author Message
zalek

External


Since: Mar 16, 2008
Posts: 8



(Msg. 1) Posted: Sat Mar 22, 2008 2:12 pm
Post subject: Accessing mainframe DB2 in Java.
Archived from groups: comp>databases>ibm-db2, others (more info?)

Hello,

I am a mainframe Cobol programmer (yes - Cobol programmers are still
around, mostly in caves) and I am writing a java code to access DB2.
In a Cobol world after each SQL command we are checking for return
conditions like success (sqlcode=0), not found (sqlcode = +100),
duplicates (sqlcode=803) and more.
How do you check for this conditions in Java?

Thanks,

Zalek

 >> Stay informed about: Accessing mainframe DB2 in Java. 
Back to top
Login to vote
zalek

External


Since: Mar 16, 2008
Posts: 8



(Msg. 2) Posted: Sat Mar 22, 2008 2:28 pm
Post subject: Re: Accessing mainframe DB2 in Java. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Mar 22, 5:14 pm, Arne Vajhøj <a... RemoveThis @vajhoej.dk> wrote:
> zalek wrote:
> > I am a mainframe Cobol programmer (yes - Cobol programmers are still
> > around, mostly in caves) and I am writing a java code to access DB2.
> > In a Cobol world after each SQL command we are checking for return
> > conditions like success (sqlcode=0), not found (sqlcode = +100),
> > duplicates (sqlcode=803) and more.
> > How do you check for this conditions in Java?
>
> Usually (possible always) the JDBC driver will throw an SQLException
> if not success.
>
> Arne

Yes - I know - but I would like to know what exactly happen. For
example - if I try to access a table using a variable as a key - I
would like to know "not found conditions" occurred to display correct
message. If database was down - I would like to know it too. Is there
a way in a java world to find it?

Thanks,

Zalek

 >> Stay informed about: Accessing mainframe DB2 in Java. 
Back to top
Login to vote
Mark Space

External


Since: Mar 22, 2008
Posts: 12



(Msg. 3) Posted: Sat Mar 22, 2008 2:28 pm
Post subject: Re: Accessing mainframe DB2 in Java. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

zalek wrote:
> Hello,
>
> I am a mainframe Cobol programmer (yes - Cobol programmers are still
> around, mostly in caves) and I am writing a java code to access DB2.

Run Zalek!

Run to the light!
 >> Stay informed about: Accessing mainframe DB2 in Java. 
Back to top
Login to vote
Arne_Vajhøj

External


Since: Mar 02, 2008
Posts: 36



(Msg. 4) Posted: Sat Mar 22, 2008 5:14 pm
Post subject: Re: Accessing mainframe DB2 in Java. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

zalek wrote:
> I am a mainframe Cobol programmer (yes - Cobol programmers are still
> around, mostly in caves) and I am writing a java code to access DB2.
> In a Cobol world after each SQL command we are checking for return
> conditions like success (sqlcode=0), not found (sqlcode = +100),
> duplicates (sqlcode=803) and more.
> How do you check for this conditions in Java?

Usually (possible always) the JDBC driver will throw an SQLException
if not success.

Arne
 >> Stay informed about: Accessing mainframe DB2 in Java. 
Back to top
Login to vote
Arne_Vajhøj

External


Since: Mar 02, 2008
Posts: 36



(Msg. 5) Posted: Sat Mar 22, 2008 7:02 pm
Post subject: Re: Accessing mainframe DB2 in Java. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

zalek wrote:
> On Mar 22, 5:14 pm, Arne Vajhøj <a... RemoveThis @vajhoej.dk> wrote:
>> zalek wrote:
>>> I am a mainframe Cobol programmer (yes - Cobol programmers are still
>>> around, mostly in caves) and I am writing a java code to access DB2.
>>> In a Cobol world after each SQL command we are checking for return
>>> conditions like success (sqlcode=0), not found (sqlcode = +100),
>>> duplicates (sqlcode=803) and more.
>>> How do you check for this conditions in Java?
>> Usually (possible always) the JDBC driver will throw an SQLException
>> if not success.
>
> Yes - I know - but I would like to know what exactly happen. For
> example - if I try to access a table using a variable as a key - I
> would like to know "not found conditions" occurred to display correct
> message. If database was down - I would like to know it too. Is there
> a way in a java world to find it?

e.getErrorCode() will give you SQLCODE number.
e.getSQLState() wil give you SQLSTATE number.
e.getMessage() will give you the entire message.

Example:

} catch (SQLException e) {
System.out.println(e.getErrorCode());
System.out.println(e.getSQLState());
System.out.println(e.getMessage());

print:

-104
42601
DB2 SQL error: SQLCODE: -104, SQLSTATE: 42601, SQLERRMC:
END-OF-STATEMENT;SELECT x* FROM T1;<table_expr>

Arne
 >> Stay informed about: Accessing mainframe DB2 in Java. 
Back to top
Login to vote
Mark Space

External


Since: Mar 22, 2008
Posts: 12



(Msg. 6) Posted: Sat Mar 22, 2008 7:02 pm
Post subject: Re: Accessing mainframe DB2 in Java. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Arne Vajhøj wrote:
> zalek wrote:
>> On Mar 22, 5:14 pm, Arne Vajhøj <a... RemoveThis @vajhoej.dk> wrote:
>>> zalek wrote:
>>>> I am a mainframe Cobol programmer (yes - Cobol programmers are still
>>>> around, mostly in caves) and I am writing a java code to access DB2.
>>>> In a Cobol world after each SQL command we are checking for return
>>>> conditions like success (sqlcode=0), not found (sqlcode = +100),
>>>> duplicates (sqlcode=803) and more.
>>>> How do you check for this conditions in Java?
>>> Usually (possible always) the JDBC driver will throw an SQLException
>>> if not success.
>>
>> Yes - I know - but I would like to know what exactly happen. For
>> example - if I try to access a table using a variable as a key - I
>> would like to know "not found conditions" occurred to display correct
>> message. If database was down - I would like to know it too. Is there
>> a way in a java world to find it?
>
> e.getErrorCode() will give you SQLCODE number.

Duh. You know I looked right at that in the Javadocs and because it
didn't say "getVendorCode" I didn't read any further? Ouch.
 >> Stay informed about: Accessing mainframe DB2 in Java. 
Back to top
Login to vote
Mark Space

External


Since: Mar 22, 2008
Posts: 12



(Msg. 7) Posted: Sat Mar 22, 2008 9:36 pm
Post subject: Re: Accessing mainframe DB2 in Java. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

zalek wrote:
> Hello,
>
> I am a mainframe Cobol programmer (yes - Cobol programmers are still
> around, mostly in caves) and I am writing a java code to access DB2.
> In a Cobol world after each SQL command we are checking for return
> conditions like success (sqlcode=0), not found (sqlcode = +100),
> duplicates (sqlcode=803) and more.
> How do you check for this conditions in Java?
>
> Thanks,
>
> Zalek

I'm going to guess:

I see SQLException has a constructor that takes a vendor specific return
code ("vendorCode"). I think you'll have to either 1) parse the
toString() result (or similar string result) or 2) use reflection to
peek at the internal vendorCode variable.

Ugly as it is, I think the second method might actually be more reliable.
 >> Stay informed about: Accessing mainframe DB2 in Java. 
Back to top
Login to vote
i.dont.need

External


Since: Mar 23, 2008
Posts: 1



(Msg. 8) Posted: Sun Mar 23, 2008 8:22 pm
Post subject: Re: Accessing mainframe DB2 in Java. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

zalek wrote:
> Hello,
>
> I am a mainframe Cobol programmer (yes - Cobol programmers are still
> around, mostly in caves) and I am writing a java code to access DB2.
> In a Cobol world after each SQL command we are checking for return
> conditions like success (sqlcode=0), not found (sqlcode = +100),
> duplicates (sqlcode=803) and more.

If you intend to write to the db directly, rather than via ORM, then I'd
recommend using Spring's JDBC facilities. Their approach to this issue
is to rethrow much more specific exceptions outlining what went wrong. I
find this to be marginally better, but the real benefit of Spring here
is getting rid of all that horrid boiler plate code that one must write
with straight JDBC. If your intent is to learn, then try a few methods
both ways and see for yourself.

--
Shane
 >> Stay informed about: Accessing mainframe DB2 in Java. 
Back to top
Login to vote
Mickey

External


Since: Mar 25, 2008
Posts: 1



(Msg. 9) Posted: Tue Mar 25, 2008 11:14 am
Post subject: Re: Accessing mainframe DB2 in Java. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Mark Space wrote:
> zalek wrote:
> > Hello,
> >
> > I am a mainframe Cobol programmer (yes - Cobol programmers are still
> > around, mostly in caves) and I am writing a java code to access DB2.
>
> Run Zalek!
>
> Run to the light!

As verbose and ungainly as Cobol is, I'd prefer it any day to Java.
Then again, I'd prefer a sharp object in the eye to Java.

Mickey - Rexx rules Smile))))
 >> Stay informed about: Accessing mainframe DB2 in Java. 
Back to top
Login to vote
Alex.From.Ohio.Java

External


Since: Mar 16, 2008
Posts: 2



(Msg. 10) Posted: Tue Mar 25, 2008 11:45 am
Post subject: Re: Accessing mainframe DB2 in Java. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Mar 25, 2:14 pm, Mickey <mick... DeleteThis @comcast.net> wrote:
> As verbose and ungainly as Cobol is, I'd prefer it any day to Java.

And you are right! Stay in your world.
It's wonderful and amazing.
Never saw anything like this one.
They even blame Java in their own faults...

We had project where we had connection to at least half of dozen
different database platforms. But only DB2 Connect tried to charge us
for $6,000 for single query. From mainframe side, of course. And they
killed this project because it was "too expensive to connect to DB2".

It was very efficient to connect to DB2 with Cobol (but they didn't
tell us what price would it be). However it was impossible to connect
to other databases from mainframe side and project was finally
canceled as impossible to create.

Alex.
http://www.myjavaserver.com/~alexfromohio/
 >> Stay informed about: Accessing mainframe DB2 in Java. 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Newbie - problem accessing DB2 with Java program. - In my installation we have DB2 on a mainframe computer. I am able to access DB2 from my PC (WinXP) using some utilities. I wrote a Java program to access DB2, but I am getting errors. After command: Class.forName("COM.ibm.db2.jdbc.app.DB2Driver&quot...

Java Requierment - Hi, Dear business partners we have an urgent requirement on .net developer Thanks & Regards Pavani.c2c@gmail.com Pavani_savvy@gmail.com

Need to Learn about the Java ODBC - From February to July of last year I worked for a company where I wrote C code that accessed a PostgreSQL database with SQL commands and generated the output my supervisor wanted. Now I'm working for a different company that doesn't have a C..

free database for java - Hello. I am looking for best free database for java & navigator tool (Till I found someone to invest on my software ...) After I have asked some people : I have found Derby db & Squirrel-sql db-navigator. .... but I see some opinions that Derb...

Java Database for mobile phone - I'm searching for a simple Java database for mobile phone (motorola v550). I would like to create a database with few fields containing texts. Is there some free/shareware software? Is there a very simple Java spreadsheet for mobile phone motorola v550?...
   Database Help (Home) -> Java All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]