Hi Rony,

you're totally right – and found the solution, as you can see below . It works!!!

Thanks a lot for your help (for the moment ;-))

Regards

Roger

 

The code:

syntax:

trace i

-- fragment that should reside in your syntax condition handling code

 

   jexc=condition("Additional")~at(2)   -- second entry in the ooRexx array

   say "jexc:" jexc

   say "jexc~toString:" jexc~toString   -- let the Java object create a string value

 

   jobj=jexc~getTargetException  -- <== fetch the original exception

   say "jobj:" jobj 

   say "jobj~toString:" jobj~toString   -- let the Java object create a string value

  

   jobj=jobj~getCause -- replace the Rexx variable with the causing Java exception object

   say "jobj now:" jobj

   say "jobj~toString:" jobj~toString   -- let the Java object create a string value

 

 

   if jobj~bsf.isA('com.ibm.db2.jcc.DB2Diagnosable') then

   do

      -- now you know that that exception has all methods from DB2Diagnosable!

       sqlca=jobj~getSqlca

       say "sqlCode ="sqlca~getSqlCode

       say "sqlState="sqlca~sqlState   -- note: BSF4ooRexx treats Java "get" methods as ooRexx getter methods (one can omit the prefix "get" in ooRexx)

       say "sqlMsg  ="sqlca~getMessage

       say "sqlErrmcTokens =" sqlca~getSqlErrmcTokens

       say "sqlErrd ="sqlca~getSqlErrd

       say "sqlErrp ="sqlca~getSqlErrp

       say "sqlErrmc =" sqlca~getSqlErrmc

       say "sqlWarn ="sqlca~getSqlWarn

       -- ...

   end

  return

 

The results:

jexc: org.apache.bsf.BSFException@11b1db9a

jexc~toString: org.apache.bsf.BSFException: /// Java-exception (RexxAndJava) occurred: [java.lang.reflect.InvocationTargetException], getCause():

[com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=as;select count(* ;), DRIVER=3.64.114] \\\

BSF4ooRexx subfunction "invoke": object 'com.ibm.db2.jcc.am.io@59f55efc' - method [EXECUTEQUERY], method not found or error (exception) executing

method!

jobj: java.lang.reflect.InvocationTargetException@1a33f652

jobj~toString: java.lang.reflect.InvocationTargetException

jobj now: com.ibm.db2.jcc.am.SqlSyntaxErrorException@7f575ec

jobj~toString: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=as;select count(* ;), DRIVER=3.6

4.114

sqlCode =-104

sqlState=42601

sqlMsg  =Auf "select count(* " folgte das unerwartete Token "as".  Zu den möglichen Token gehören: ")".. SQLCODE=-104, SQLSTATE=42601, DRIVER=3.6

4.114

sqlErrmcTokens = [Ljava.lang.String;@1910cd6d

sqlErrd =[I@1098e5da

sqlErrp =SQLNP01F

sqlErrmc = as;select count(* ;)

sqlWarn =[C@a6eaa3a

 

And – maybe for more understanding – the trace output:

 

       >L>   "select count(* as total_fans from test"

       >A>   "select count(* as total_fans from test"

    68 *-* syntax:

    69 *-* trace i

    72 *-* jexc=condition("Additional")~at(2)   -- second entry in the ooRexx array

       >L>   "Additional"

       >A>   "Additional"

       >F>   CONDITION => "an Array"

       >L>   "2"

       >A>   "2"

      >M>   "AT" => "org.apache.bsf.BSFException@2abeb8f0"

       >>>   "org.apache.bsf.BSFException@2abeb8f0"

       >=>   JEXC <= "org.apache.bsf.BSFException@2abeb8f0"

    73 *-* say "jexc:" jexc

       >L>   "jexc:"

       >V>   JEXC => "org.apache.bsf.BSFException@2abeb8f0"

       >O>   " " => "jexc: org.apache.bsf.BSFException@2abeb8f0"

       >>>   "jexc: org.apache.bsf.BSFException@2abeb8f0"

jexc: org.apache.bsf.BSFException@2abeb8f0

    74 *-* say "jexc~toString:" jexc~toString   -- let the Java object create a string value

       >L>   "jexc~toString:"

       >V>   JEXC => "org.apache.bsf.BSFException@2abeb8f0"

       >M>   "TOSTRING" => "org.apache.bsf.BSFException: /// Java-exception (RexxAndJava) occurred: [java.lang.reflect.InvocationTargetException]

, getCause(): [com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=as;select count(* ;), DRIVER=3.6

4.114] \\\?BSF4ooRexx subfunction "invoke": object 'com.ibm.db2.jcc.am.io@59f55efc' - method [EXECUTEQUERY], method not found or error (exception

) executing method!"

       >O>   " " => "jexc~toString: org.apache.bsf.BSFException: /// Java-exception (RexxAndJava) occurred: [java.lang.reflect.InvocationTargetEx

ception], getCause(): [com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=as;select count(* ;), DR

IVER=3.64.114] \\\?BSF4ooRexx subfunction "invoke": object 'com.ibm.db2.jcc.am.io@59f55efc' - method [EXECUTEQUERY], method not found or error (e

xception) executing method!"

       >>>   "jexc~toString: org.apache.bsf.BSFException: /// Java-exception (RexxAndJava) occurred: [java.lang.reflect.InvocationTargetException

], getCause(): [com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=as;select count(* ;), DRIVER=3.

64.114] \\\?BSF4ooRexx subfunction "invoke": object 'com.ibm.db2.jcc.am.io@59f55efc' - method [EXECUTEQUERY], method not found or error (exceptio

n) executing method!"

jexc~toString: org.apache.bsf.BSFException: /// Java-exception (RexxAndJava) occurred: [java.lang.reflect.InvocationTargetException], getCause():

[com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=as;select count(* ;), DRIVER=3.64.114] \\\

BSF4ooRexx subfunction "invoke": object 'com.ibm.db2.jcc.am.io@59f55efc' - method [EXECUTEQUERY], method not found or error (exception) executing

method!

    76 *-* jobj=jexc~getTargetException  -- <== fetch the original exception

       >V>   JEXC => "org.apache.bsf.BSFException@2abeb8f0"

       >M>   "GETTARGETEXCEPTION" => "java.lang.reflect.InvocationTargetException@47c3666a"

       >>>   "java.lang.reflect.InvocationTargetException@47c3666a"

       >=>   JOBJ <= "java.lang.reflect.InvocationTargetException@47c3666a"

    77 *-* say "jobj:" jobj

       >L>   "jobj:"

       >V>   JOBJ => "java.lang.reflect.InvocationTargetException@47c3666a"

       >O>   " " => "jobj: java.lang.reflect.InvocationTargetException@47c3666a"

       >>>   "jobj: java.lang.reflect.InvocationTargetException@47c3666a"

jobj: java.lang.reflect.InvocationTargetException@47c3666a

    78 *-* say "jobj~toString:" jobj~toString   -- let the Java object create a string value

       >L>   "jobj~toString:"

       >V>   JOBJ => "java.lang.reflect.InvocationTargetException@47c3666a"

       >M>   "TOSTRING" => "java.lang.reflect.InvocationTargetException"

       >O>   " " => "jobj~toString: java.lang.reflect.InvocationTargetException"

       >>>   "jobj~toString: java.lang.reflect.InvocationTargetException"

jobj~toString: java.lang.reflect.InvocationTargetException

    80 *-* jobj=jobj~getCause -- replace the Rexx variable with the causing Java exception object

       >V>   JOBJ => "java.lang.reflect.InvocationTargetException@47c3666a"

       >M>   "GETCAUSE" => "com.ibm.db2.jcc.am.SqlSyntaxErrorException@49708eee"

       >>>   "com.ibm.db2.jcc.am.SqlSyntaxErrorException@49708eee"

       >=>   JOBJ <= "com.ibm.db2.jcc.am.SqlSyntaxErrorException@49708eee"

    81 *-* say "jobj now:" jobj

       >L>   "jobj now:"

       >V>   JOBJ => "com.ibm.db2.jcc.am.SqlSyntaxErrorException@49708eee"

       >O>   " " => "jobj now: com.ibm.db2.jcc.am.SqlSyntaxErrorException@49708eee"

       >>>   "jobj now: com.ibm.db2.jcc.am.SqlSyntaxErrorException@49708eee"

jobj now: com.ibm.db2.jcc.am.SqlSyntaxErrorException@49708eee

    82 *-* say "jobj~toString:" jobj~toString   -- let the Java object create a string value

       >L>   "jobj~toString:"

       >V>   JOBJ => "com.ibm.db2.jcc.am.SqlSyntaxErrorException@49708eee"

       >M>   "TOSTRING" => "com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=as;select count(* ;

), DRIVER=3.64.114"

       >O>   " " => "jobj~toString: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=as;select c

ount(* ;), DRIVER=3.64.114"

       >>>   "jobj~toString: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=as;select count(*

;), DRIVER=3.64.114"

jobj~toString: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=as;select count(* ;), DRIVER=3.6

4.114

    85 *-* if jobj~bsf.isA('com.ibm.db2.jcc.DB2Diagnosable')

       >V>   JOBJ => "com.ibm.db2.jcc.am.SqlSyntaxErrorException@49708eee"

       >L>   "com.ibm.db2.jcc.DB2Diagnosable"

       >A>   "com.ibm.db2.jcc.DB2Diagnosable"

       >M>   "BSF.ISA" => "1"

       >>>   "1"

    85 *-*   then

    86 *-*     do

    88 *-*       sqlca=jobj~getSqlca

       >V>         JOBJ => "com.ibm.db2.jcc.am.SqlSyntaxErrorException@49708eee"

       >M>         "GETSQLCA" => "com.ibm.db2.jcc.t4.T4Sqlca@7a84770a"

       >>>         "com.ibm.db2.jcc.t4.T4Sqlca@7a84770a"

       >=>         SQLCA <= "com.ibm.db2.jcc.t4.T4Sqlca@7a84770a"

    89 *-*       say "sqlCode ="sqlca~getSqlCode

       >L>         "sqlCode ="

       >V>         SQLCA => "com.ibm.db2.jcc.t4.T4Sqlca@7a84770a"

       >M>         "GETSQLCODE" => "-104"

       >O>         "" => "sqlCode =-104"

       >>>         "sqlCode =-104"

sqlCode =-104

    90 *-*       say "sqlState="sqlca~sqlState   -- note: BSF4ooRexx treats Java "get" methods as ooRexx getter methods (one can omit the prefix

"get" in ooRexx)

       >L>         "sqlState="

       >V>         SQLCA => "com.ibm.db2.jcc.t4.T4Sqlca@7a84770a"

       >M>         "SQLSTATE" => "42601"

       >O>         "" => "sqlState=42601"

       >>>         "sqlState=42601"

sqlState=42601

    91 *-*       say "sqlMsg  ="sqlca~getMessage

       >L>         "sqlMsg  ="

       >V>         SQLCA => "com.ibm.db2.jcc.t4.T4Sqlca@7a84770a"

       >M>         "GETMESSAGE" => "Auf "select count(* " folgte das unerwartete Token "as".  Zu den möglichen Token gehören: ")".. SQLCODE=-104,

SQLSTATE=42601, DRIVER=3.64.114"

       >O>         "" => "sqlMsg  =Auf "select count(* " folgte das unerwartete Token "as".  Zu den möglichen Token gehören: ")".. SQLCODE=-104,

SQLSTATE=42601, DRIVER=3.64.114"

       >>>         "sqlMsg  =Auf "select count(* " folgte das unerwartete Token "as".  Zu den möglichen Token gehören: ")".. SQLCODE=-104, SQLSTA

TE=42601, DRIVER=3.64.114"

sqlMsg  =Auf "select count(* " folgte das unerwartete Token "as".  Zu den möglichen Token gehören: ")".. SQLCODE=-104, SQLSTATE=42601, DRIVER=3.6

4.114

    92 *-*       say "sqlErrmcTokens =" sqlca~getSqlErrmcTokens

       >L>         "sqlErrmcTokens ="

       >V>         SQLCA => "com.ibm.db2.jcc.t4.T4Sqlca@7a84770a"

       >M>         "GETSQLERRMCTOKENS" => "[Ljava.lang.String;@2a862557"

       >O>         " " => "sqlErrmcTokens = [Ljava.lang.String;@2a862557"

       >>>         "sqlErrmcTokens = [Ljava.lang.String;@2a862557"

sqlErrmcTokens = [Ljava.lang.String;@2a862557

    93 *-*       say "sqlErrd ="sqlca~getSqlErrd

       >L>         "sqlErrd ="

       >V>         SQLCA => "com.ibm.db2.jcc.t4.T4Sqlca@7a84770a"

       >M>         "GETSQLERRD" => "[I@551eef55"

       >O>         "" => "sqlErrd =[I@551eef55"

       >>>         "sqlErrd =[I@551eef55"

sqlErrd =[I@551eef55

    94 *-*       say "sqlErrp ="sqlca~getSqlErrp

       >L>         "sqlErrp ="

       >V>         SQLCA => "com.ibm.db2.jcc.t4.T4Sqlca@7a84770a"

       >M>         "GETSQLERRP" => "SQLNP01F"

       >O>         "" => "sqlErrp =SQLNP01F"

       >>>         "sqlErrp =SQLNP01F"

sqlErrp =SQLNP01F

    95 *-*       say "sqlErrmc =" sqlca~getSqlErrmc

       >L>         "sqlErrmc ="

       >V>         SQLCA => "com.ibm.db2.jcc.t4.T4Sqlca@7a84770a"

       >M>         "GETSQLERRMC" => "as;select count(* ;)"

       >O>         " " => "sqlErrmc = as;select count(* ;)"

       >>>         "sqlErrmc = as;select count(* ;)"

sqlErrmc = as;select count(* ;)

    96 *-*       say "sqlWarn ="sqlca~getSqlWarn

       >L>         "sqlWarn ="

       >V>         SQLCA => "com.ibm.db2.jcc.t4.T4Sqlca@7a84770a"

       >M>         "GETSQLWARN" => "[C@1098e5da"

       >O>         "" => "sqlWarn =[C@1098e5da"

       >>>         "sqlWarn =[C@1098e5da"

sqlWarn =[C@1098e5da

    98 *-*   end

   101 *-* return

Von: Rony G. Flatscher [mailto:Rony.Flatscher@wu.ac.at]
Gesendet: Dienstag, 13. August 2013 13:25
An: bsf4oorexx-support@lists.sourceforge.net
Betreff: Re: [Bsf4oorexx-support] Exception handling with BSF4oorexx and JDBC and DB2

 

Hi Roger,

o.k., we need probably one more step. the BSFException Java exception object in this case wraps an InvocationTargetException Java exception object, which we need to ask for the causing exception. :)


Now, first what you could and should do is, check out the Java documentation for java.lang.reflect.InvocationTargetException. As you have probably no working experience with Java (and should not need to have one) I suggest that you point your browser to the Java documentation of a rather old version, namely Java 1.4: <http://docs.oracle.com/javase/1.4.2/docs/api/>.

You need to get acquainted with this HTML-based Java documentation. Search for "InvocationTargetException" in the left bottom navigation area, which lists all Java classes and click on it. Then you will see the documentation in the main window. In this case you learn, that objects of this class implement the methods getCause() and getTargetException(). So we now know what messages we can send to that Java object.

As a result change the code to:

-- fragment that should reside in your syntax condition handling code
 
   jexc=condition("Additional")~at(2)   -- second entry in the ooRexx array
   say "jexc:" jexc
   say "jexc~toString:" jexc~toString   -- let the Java object create a string value
   say "---"
 
   jobj=jexc~getTargetException  -- <== fetch the original exception
   say "jobj:" jobj  
   say "jobj~toString:" jobj~toString   -- let the Java object create a string value
   say "---"
 
   jobj=jobj~getCause -- replace the Rexx variable with the causing Java exception object
   say "jobj now:" jobj
   say "jobj~toString:" jobj~toString   -- let the Java object create a string value
 
   if jobj~bsf.isA('com.ibm.db2.jcc.DB2Diagnosable') then
   do
       -- now you know that that exception has all methods from DB2Diagnosable!
       sqlca=jobj~getSclca
       say "sqlCode ="sqlca~getSqlCode 
       say "sqlState="sqlca~sqlState   -- note: BSF4ooRexx treats Java "get" methods as ooRexx getter methods (one can omit the prefix "get" in ooRexx)
       say "sqlMsg  ="sqlca~sqlMessage
       -- ...
   end

HTH,

---rony

P.S.: The latest Java documentation for Java 1.7 can be found at: <http://docs.oracle.com/javase/7/docs/api/>. Starting with the introduction of generics in Java 1.5 (also dubbed Java 5 for marketing purposes) the documentaiton gets harder to read because of the usage of angel brackets with "generic" information in it. As a rule of thumb, just ignore those angle brackets, pretend they do not exist at all. Generics are important for statically typed languages, not for dynamically typed ones as ooRexx.