473,387 Members | 1,603 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,387 software developers and data experts.

How do you display the Current SQLSTATE or SQLCODE

Question:
I come from a COBOL/DB2 environment so I am use to being able to display the current SQLSTATE or SQLCODE following the issuing of a DB2 command, now I have move over to a LINUX/DB2 shell scripting environment and I am looking to see if it is possible for me to do the same in a shell script.

So is it possible to display the current sqlcode or sqlstate and only the sqlcode or sqlstate?
Could someone please give me an example?

Thank You
Feb 5 '08 #1
2 8145
Question:
I come from a COBOL/DB2 environment so I am use to being able to display the current SQLSTATE or SQLCODE following the issuing of a DB2 command, now I have move over to a LINUX/DB2 shell scripting environment and I am looking to see if it is possible for me to do the same in a shell script.

So is it possible to display the current sqlcode or sqlstate and only the sqlcode or sqlstate?
Could someone please give me an example?

Thank You
I will answer my own question:

Expand|Select|Wrap|Line Numbers
  1. sqlcode=`db2 -ec +o "Enter your db2 statement here"`
The –ec switch is interpreted as display sqlcode; to display sqlstate use –es.

I hope this helps other people out there.
Feb 6 '08 #2
docdiesel
297 Expert 100+
Hi,

first, I reformatted your last post slightly for better readability. Second, thanks a lot for posting your solution and sharing with us! Third, the shell is saving the return code of the last command in the variable "$?" which could be useful for you, too. If everything was OK, DB2 (and most unix/linux commands) return 0 (which means true). Error returns false which is something different than 0 (usually 1) and the value may be giving you additional hints what went wrong.

Expand|Select|Wrap|Line Numbers
  1. OUT=` db2 -es +o "your sql statement" `
  2. echo DB2 return code is ${?}
  3. echo DB2 sqlstate is ${OUT}
Regards,

Bernd
Feb 6 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Sean C. | last post by:
Helpful folks, I have recently migrated our test server, which runs Win NT 4, from V7.2 FP11 to V8.1.3. Just about everything works wondefully, except I am having major problems getting the...
5
by: Jean-Marc Blaise | last post by:
Dear all, Could you explain why some SQL messages do not possess a SQLSTATE ? Why not transmitting the SQLSTATE of the original <sqlcode>, for example if you get a -911 on a RUNSTATS ? ...
0
by: SKC | last post by:
What I did before problem occured? Ans : When I REVOKE teh EXECUTE from a STORED PROCS called (SP1). and then re GRANTED the EXECUTE permission to SP1. SP1 is a SQL procedure on version 8 UDB....
4
by: Bob Stearns | last post by:
Given the DDL: CREATE TABLE JOHNTEST.TASK_LIST ( TASK BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1, CACHE 20) NOT NULL, PRI CHAR(1) NOT NULL, SUBP...
1
by: xf wang via DBMonster.com | last post by:
when i call db2 store producedure,db2 throws exception whose sqlstate is identical t0 38503.I find information as follows: DB2 does check for certain types of limited actions that erroneously...
1
by: tmugavero | last post by:
Hello, This is my first time starting a topic here so I hope this is the right place. I am having problems running SQL queries on a Version 8 DB2 database for Windows Server using the type 4...
2
by: Richard | last post by:
Our web programmer was looking in his application log an found the following error: 2006-08-31 16:33:35,129 ERROR org.hibernate.util.JDBCExceptionReporter - < SQL0723N An error occurred in a...
5
by: misterutterbag | last post by:
Stack trace below. Only happens in WebSphere 6.0. DB2 v 8.2. FP12. Only against 1 database. I have other databases in this database instance, but they don't seem to have this problem. ...
3
by: Gene McCusker | last post by:
I am getting an SQLCODE = -4700, SQLSTATE = 56038 on Below SQL returned - SQLCODE = -4700, SQLSTATE = 56038 We are on version 8 of DB2 but not in NFM yet UPDATE CORETSTA.DDA C ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.