5454import com .sun .btrace .annotations .OnEvent ;
5555import com .sun .btrace .annotations .OnMethod ;
5656import com .sun .btrace .annotations .TLS ;
57+ import com .sun .btrace .annotations .Return ;
58+ import com .sun .btrace .annotations .Self ;
5759
5860/**
5961 * BTrace script to print timings for all executed JDBC statements on an event. Demonstrates
@@ -105,7 +107,7 @@ public class JdbcQueries {
105107 */
106108 @ OnMethod (clazz = "+java.sql.Connection" , method = "/prepare.*/" )
107109 public static void onPrepare (AnyType [] args ) {
108- preparingStatement = useStackTrace ? jstackStr () : str (args [1 ]);
110+ preparingStatement = useStackTrace ? jstackStr () : str (args [0 ]);
109111 }
110112
111113 /**
@@ -115,10 +117,9 @@ public static void onPrepare(AnyType[] args) {
115117 * the return value from the prepareXxx() method.
116118 */
117119 @ OnMethod (clazz = "+java.sql.Connection" , method = "/prepare.*/" , location = @ Location (Kind .RETURN ))
118- public static void onPrepareReturn (AnyType arg ) {
120+ public static void onPrepareReturn (@ Return Statement preparedStatement ) {
119121 if (preparingStatement != null ) {
120122 print ("P" ); // Debug Prepared
121- Statement preparedStatement = (Statement ) arg ;
122123 put (preparedStatementDescriptions , preparedStatement , preparingStatement );
123124 preparingStatement = null ;
124125 }
@@ -129,14 +130,13 @@ public static void onPrepareReturn(AnyType arg) {
129130 // Otherwise the SQL is in the first argument.
130131
131132 @ OnMethod (clazz = "+java.sql.Statement" , method = "/execute.*/" )
132- public static void onExecute (AnyType [] args ) {
133- if (args .length == 1 ) {
133+ public static void onExecute (@ Self Statement currentStatement , AnyType [] args ) {
134+ if (args .length == 0 ) {
134135 // No SQL argument; lookup the SQL from the prepared statement
135- Statement currentStatement = (Statement ) args [0 ]; // this
136136 executingStatement = get (preparedStatementDescriptions , currentStatement );
137137 } else {
138138 // Direct SQL in the first argument
139- executingStatement = useStackTrace ? jstackStr () : str (args [1 ]);
139+ executingStatement = useStackTrace ? jstackStr () : str (args [0 ]);
140140 }
141141 }
142142
0 commit comments