473,729 Members | 2,235 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unable to Debug Java SP in Stored Procedure Builder

Running DB2 v7 UDB ("DB2 v7.1.0.93", "n031208" and "WR21333") on Windows XP,
I am unable to find out why the "Build for Debug" option within Stored
Procedure Builder is not enabled on Java stored procedures. It is enabled
for SQL stored procedures.

It is possible to "Build" and "Run" the Java SPs, it just isn't possible to
click on the "Build for Debug" option. Thanks for any help in advance.

Michael
Dec 5 '05 #1
2 3147

"Michael" <in************ *@nowhere.com> wrote in message
news:WH******** **********@news 20.bellglobal.c om...
Running DB2 v7 UDB ("DB2 v7.1.0.93", "n031208" and "WR21333") on Windows
XP, I am unable to find out why the "Build for Debug" option within Stored
Procedure Builder is not enabled on Java stored procedures. It is enabled
for SQL stored procedures.

It is possible to "Build" and "Run" the Java SPs, it just isn't possible
to click on the "Build for Debug" option. Thanks for any help in advance.

I was never able to get the Debugger to work for Java SPs either, despite
carefully following all instructions that were supposed to work; they worked
for many others but never for me. Mind you, I've never been great with
installing and configuring!

Let me suggest that you search the archives via Google Groups for the
technique of getting the debugger to work with Java SPs in Version 7 of UDB:
they may well work for you. Or consider upgrading to Version 8.

If an upgrade to Version 8 isn't possible and you can't get the debugger to
work, you can always resort to more old-fashioned techniques. I debugged
several Java SPs by writing System.out.prin tln() statements to a simple log.

In fact, I even wrote a class called DB2RoutineLogge r which I call from my
Java stored procs and UDFs. Here is the code for that class, followed by an
illustration of the technique for invoking it. It's not as nice as a full
screen interactive debugger but it does the job....

------------------------------------------------------------------------------------------------
package com.mydomain.ud f.java;

import java.io.Buffere dWriter;
import java.io.File;
import java.io.FileWri ter;
import java.io.IOExcep tion;
import java.io.PrintWr iter;
import java.io.StringW riter;
import java.text.Simpl eDateFormat;
import java.util.Date;
import java.util.Local e;

/**
* @author Rhino
*
*/
public class DB2RoutineLogge r {

/*
*
* Variables and constants needed to support logging of this UDF.
*
*/

/**
* The path identifying the directory where the log will be written if
the
* program is running on a Windows operating system, e.g. Windows 2000,
* Windows XP. NOTE: The file separator character for Windows, '\',
needs to
* be written TWICE each time it occurs; the first backslash in each
pair is
* the Java escape character and the second backslash in each pair is
the
* actual file separator. Example: "C:\\RDS\\l ogs"
*/
private String logPathWindows = "C:\\RDS\\logs" ;

/**
* The path identifying the directory where the log will be written if
the
* program is running on a Unix operating system, e.g. AIX/6000, Linux.
* Example: "/home/rds/logs"
*/
private String logPathUnix = "/home/rds/logs";

/**
* The text that will begin all logging-related error messages to the
user,
* assuring them that they did nothing wrong and telling them (and
reminding
* support staff) that further information is available in DB2's
db2diag.log
* file, which is usually situated in SQLLIB\DB2.
*
* DB2 is only capable of showing around 40 characters worth of
* programmer-supplied text in the SQL4302N message that is displayed
when
* the program throws an exception. Since the following text is the most
* important information for the *USER* to see, this is made the leading
* part of the information that is displayed. Additional information is
* normally written to the db2diag.log for the use of systems personnel
in
* diagnosing the problem.
*/
private static final String USER_MESSAGE = "Internal error. Support: See
db2diag.log. ";

/** The desired format of the timestamp used in the log. */
private static final String TIMESTAMP_PATTE RN = "yyyy-MM-dd
HH.mm.ss.SSS";

/**
* The Simple Date Format that will be used for creating the current
* timestamp.
*/
private static final SimpleDateForma t TIMESTAMP_FORMA T = new
SimpleDateForma t(
TIMESTAMP_PATTE RN, Locale.getDefau lt());

/** The log file which is written by this class. */
private File outputFile = null;

/** A String concatenation that identifies which class has called this
class. */
private String sourceCodeLocat ion = null;
/**
* This constructor establishes a reference to an instance of the class
and creates
* the String concatenation which identifies the class which invoked the
constructor,
* which is the class that needs diagnostics generated.
*
* @param incomingPackage Name the name of the package containing the
class which invoked this class
* @param incomingClassNa me the name of the class which invoked this
class
* @param incomingMethodN ame the name of the method which invoked this
class
*/
public DB2RoutineLogge r(String incomingPackage Name, String
incomingClassNa me, String incomingMethodN ame) {

this.sourceCode Location = incomingPackage Name + "." +
incomingClassNa me + "." + incomingMethodN ame;
}
/*
*
* Utility methods used primarily to support logging.
*
*/

/**
* Set the log path for a Unix environment.
*
* @param String the desired log path in a Unix environment
*/
public void setLogPathUnix( String logPathUnix) {

this.logPathUni x = logPathUnix;
}

/**
* Get the log path for a Unix environment.
*
* @return String the log path currently set for a Unix environment
*/
public String getLogPathUnix( ) {

return logPathUnix;
}

/**
* Set the log path for a Windows environment.
*
* @param String logPathWindows the desired log path in a Windows
environment
*/
public void setLogPathWindo ws(String logPathWindows) {

this.logPathWin dows = logPathWindows;
}

/**
* Get the log path for a Windows environment.
*
* @return String the log path currently set for a Windows environment
*/
public String getLogPathWindo ws() {

return logPathWindows;
}

/**
* Method getLogPath() chooses the log path based on the operating
system name.
*
* @version 1.0
* @since 2005-03-03
*
* @return String log path
*/
public String getLogPath() {

/*
* Determine the directory in which the log file will be written
based on the
* current operating system.
*/
if (System.getProp erty("os.name") .startsWith("Wi ndows")) {
return logPathWindows;
}
else {
return logPathUnix;
}
}

/**
* Method createFile() creates an output file.
*
* <p>
* If the log file cannot be created for some reason, carry on
regardless with the
* "main mission" of the UDF. Don't inform the user. [The
System.err.prin tln()
* statements in the catch blocks are just placeholders; they won't
actually
* be written when running in a UDF.] The developer who wanted to
activate logging
* will realize that logging failed when the log isn't where it was
intended to be.
* </p>
*
* @version 1.0
* @since 2005-03-03
*
* @see #writeToFile(Bu fferedWriter, String)
* @see #closeFile(Buff eredWriter)
*
* @param path the directory path into which the file will be written
* @param fileName the name of the file which will be written
* @return BufferedWriter
*/
public BufferedWriter createFile(Stri ng path, String fileName) {

String METHOD_NAME = "createFile ()";

/*
* See if the output directory exists; if it doesn't, create it and
any
* needed parent directories.
*/
File outputPath = new File(path);
if (!outputPath.ex ists()) {
try {
outputPath.mkdi rs();
} catch (SecurityExcept ion s_excp) {
System.err.prin tln(USER_MESSAG E + "Problem:
SecurityExcepti on ("
+ s_excp.getMessa ge() + "). Code location: "
+ sourceCodeLocat ion
+ ". Programmer message: Could not create output
path, "
+ outputPath + ".");
}
}

/* See if the output file exists; if it doesn't, create it. */
outputFile = new File(outputPath , fileName);
if (!outputFile.ex ists()) {
try {
outputFile.crea teNewFile();
} catch (IOException io_excp) {
System.err.prin tln(USER_MESSAG E + "Problem: IOException ("
+ io_excp.getMess age() + "). Code location: "
+ sourceCodeLocat ion
+ ". Programmer message: Could not create log file,
" + outputFile + ".");
} catch (SecurityExcept ion s_excp) {
System.err.prin tln(USER_MESSAG E + "Problem:
SecurityExcepti on ("
+ s_excp.getMessa ge() + "). Code location: "
+ sourceCodeLocat ion
+ ". Programmer message: Could not create log file,
" + outputFile + ".");
}
}

BufferedWriter bufferedWriter = null;
/* Ensure that the FileWriter is opened in such a way that each
write appends to the file. */
try {
FileWriter fileWriter = new FileWriter(path + File.separator +
fileName, true);
bufferedWriter = new BufferedWriter( fileWriter);
} catch (IOException io_excp) {
System.err.prin tln(USER_MESSAG E + "Problem: IOException ("
+ io_excp.getMess age() + "). Code location: "
+ sourceCodeLocat ion
+ ". Programmer message: Could not create FileWriter or
BufferedWriter. ");
}

return (bufferedWriter );
}

/**
* Method writeToFile() writes a single line a file.
*
* <p>
* If the log file cannot be written for some reason, carry on
regardless with the
* "main mission" of the UDF. Don't inform the user. [The
System.err.prin tln()
* statement in the catch block is just a placeholder; it won't actually
* be written when running in a UDF.] The developer who wanted to write
to the
* log will presumably realize that there was a problem when the log is
empty
* or when some of the expected lines are missing.
* </p>
*
* @version 1.0
* @since 2005-03-03
*
* @see #createFile(Str ing, String)
*
* @param outputFile
* the BufferedWriter for the file
* @param oneLine
* the line which is to be written to the file
*/
public void writeToFile(Buf feredWriter outputFile, String oneLine) {

String METHOD_NAME = "writeToFile()" ;

/* Get the current timestamp from the system. */
Date currentDateTime = new Date(System.cur rentTimeMillis( ));

/* Format the timestamp. */
String formattedDateTi me = TIMESTAMP_FORMA T.format(curren tDateTime);

/*
* Create the locator, which concatenates the formatted current
timestamp
* and the source code location to identify exactly when a given
event took
* place and what source code initiated that event.
*/
String locator = formattedDateTi me + " - " + sourceCodeLocat ion +
" - ";

/*
* Write the incoming line of information after the locator, write a
newline,
* and then flush to ensure that all output is written to the file,
not left
* behind in the buffer.
*/
try {
outputFile.writ e(locator + oneLine);
outputFile.newL ine();
outputFile.flus h();
} catch (IOException io_excp) {
System.err.prin tln(USER_MESSAG E + "Problem: IOException ("
+ io_excp.getMess age() + "). Code location: "
+ sourceCodeLocat ion
+ ". Programmer message: Could not create write line, '"
+ oneLine + "', to log.");
}

}
/**
* Method closeFile() closes the file.
*
* <p>
* If the log file cannot be closed for some reason, carry on regardless
with the
* "main mission" of the UDF. Don't inform the user. [The
System.err.prin tln()
* statement in the catch block is just a placeholder; it won't actually
* be written when running in a UDF.] The developer who wanted to close
the log
* probably won't care if the log isn't closed and will rely on the
operating
* system to close it eventually.
* </p>
*
* @version 1.0
* @since 2005-03-03
*
* @see #createFile(Str ing, String)
*
* @param outputFile
* the BufferedWriter for the file which is to be closed
*/
public void closeFile(Buffe redWriter outputFile) {

String METHOD_NAME = "closeFile( )";

try {
outputFile.clos e();
} catch (IOException io_excp) {
System.err.prin tln(USER_MESSAG E + "Problem: IOException ("
+ io_excp.getMess age() + "). Code location: "
+ sourceCodeLocat ion
+ ". Programmer message: Could not close log.");
}
}
/**
* Method getStack() writes a stackTrace to a String, given a Throwable.
*
* <p>This is a utility method that will appear in every UDF that needs
to return
* a stackTrace.</p>
*
* @version 1.0
* @since 2004
*
* @param Throwable an Error or Exception
* @return String containing the stackTrace for the Throwable in String
format
*/
public String getStack (Throwable throwable) {

StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(str ingWriter);
throwable.print StackTrace(prin tWriter);
printWriter.clo se();

return (stringWriter.t oString());
}
}
------------------------------------------------------------------------------------------------

To invoke the DB2RoutineLogge r class from my UDF or stored procedure, I
include the following class variables in the SP or UDF:

-----------------------------------------------------------------------------------------------
/**
* If true, file logging of this UDF will be attempted. If successful,
the log output
* will be written to a file with the name specified in the 'LOG_FILE'
constant. The
* path to that file is operating system dependent; see the code in the
getLogPath()
* method.
*/
private static final boolean DO_LOGGING = true;
/**
* The name of the package. This need not be the actual package name;
instead it is used
* primarily to distinguish between UDFs that are written using
parameter style DB2GENERAL
* from UDFs written with parameter style DB2JAVA on the theory that
UDFs written for one
* parameter style will be in a different package than UDFs written in
the other parameter
* style.
*/
private static final String PACKAGE_NAME = "DB2JAVA";

/** The name of this class. */
private static final String CLASS_NAME = "Counter";

/** The name of the log file. */
private static final String LOG_FILE = "myUDFandSP.log "; //replace the
constant with a name you like better

/** The buffered writer which is used to write the log. */
private static BufferedWriter log = null;

/** The class used to write log information. */
private static DB2RoutineLogge r logger = null;
------------------------------------------------------------------------------------------------

Then, in the constructor for my SP or UDF, I include this code to create the
log file and to close it when the UDF/SP is finished:
------------------------------------------------------------------------------------------------

String METHOD_NAME = "myMethod() "; //replace the constant with the
actual method name

/*
* Create the log file and write the input parameters to the log. If
the log file
* cannot be created for some reason, this will be obvious to the
developer by the
* absence of the log file. Proceed with the "main mission" of the
UDF.
*/
if (DO_LOGGING) {
logger = new DB2RoutineLogge r(PACKAGE_NAME, CLASS_NAME,
METHOD_NAME);
log = logger.createFi le(logger.getLo gPath(), LOG_FILE);
}

// DO THE NORMAL WORK OF THE UDF or SP.

if (DO_LOGGING) {
logger.closeFil e(log);
}
------------------------------------------------------------------------------------------------

Then, every time I want to display a variable value from the SP or UDF, I
execute code like this:

------------------------------------------------------------------------------------------------
if (DO_LOGGING) {
logger.writeToF ile(log, "count: " + count); //replace 'count'
with your variable name
}

------------------------------------------------------------------------------------------------

I hope this helps.

Rhino
Dec 6 '05 #2
Hi Rhino,

Thanks for the debugging class. Despite going over various web pages,
newsgroup messages (including yours), and software documentation (DB2 and
Distributed Debugger) I haven't been able to debug the Java stored
procedures. It seems the best approach is to develop the Java code outside
of the Stored Procedure Builder (SPB) in something like Eclipse. Once it
works well the code can be pasted into SPB and DriverManager connection
calls can be updated to use the default connection established by the SP
call.

Michael

"Rhino" <no************ ***********@nos pam.com> wrote in message
news:_g******** ***********@new s20.bellglobal. com...

"Michael" <in************ *@nowhere.com> wrote in message
news:WH******** **********@news 20.bellglobal.c om...
Running DB2 v7 UDB ("DB2 v7.1.0.93", "n031208" and "WR21333") on Windows
XP, I am unable to find out why the "Build for Debug" option within
Stored Procedure Builder is not enabled on Java stored procedures. It is
enabled for SQL stored procedures.

It is possible to "Build" and "Run" the Java SPs, it just isn't possible
to click on the "Build for Debug" option. Thanks for any help in
advance.

I was never able to get the Debugger to work for Java SPs either, despite
carefully following all instructions that were supposed to work; they
worked for many others but never for me. Mind you, I've never been great
with installing and configuring!

Let me suggest that you search the archives via Google Groups for the
technique of getting the debugger to work with Java SPs in Version 7 of
UDB: they may well work for you. Or consider upgrading to Version 8.

If an upgrade to Version 8 isn't possible and you can't get the debugger
to work, you can always resort to more old-fashioned techniques. I
debugged several Java SPs by writing System.out.prin tln() statements to a
simple log.

In fact, I even wrote a class called DB2RoutineLogge r which I call from my
Java stored procs and UDFs. Here is the code for that class, followed by
an illustration of the technique for invoking it. It's not as nice as a
full screen interactive debugger but it does the job....

Dec 11 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
22142
by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my application server can talk to the database. I've determined the failure occurs when the the following statement is executed: cstmt.execute(); (due to the failure of println statements placed afterwards). I get the following error after trying to...
4
4955
by: richardshen | last post by:
DB2 V8 FP4 on W2K. After a long long time waiting.. SQL1131N DARI (Stored Procedure) process has been terminated abnormally. SQLSTATE=38503 And in DB2Diag.log
4
3190
by: Rhino | last post by:
Is it possible for a Java Stored Procedure in DB2 V7.2 (Windows) to pass a Throwable back to the calling program as an OUT parameter? If yes, what datatype should I use when registering the Throwable as an OUT parameter and what datatype should I use in the CREATE PROCEDURE and DROP PROCEDURE statements? Here's what I tried: - the method signature for the stored procedure included: Throwable throwable
1
2572
by: Raquel | last post by:
Have a question on the Stored procedure method code generated by DB2 development center for Java stored procedures. Suppose I have a requirement to return the resultset consisting of FIRSTNME, LASTNAME of all employees belonging to a particular department, following is the stored procedure method code generated by "DB2 development center": public static void sproc3mtd ( String workdept, String firstnme,
4
5825
by: Abram Friesen | last post by:
Hi all, I'm a newbie at DB2 and trying to create a simple java UDF. When I call my function, I'm receiving SQL4306N. Could someone please tell me what I'm doing wrong here? Here is my java code for a UDF that simply returns the integer value you pass it:
2
9244
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered problems doing this. I wanted to implemented a generic "Helper" class like this: /** * Helper
0
1268
by: JollyK | last post by:
Hello folks, Previously I have debugged stored procedures with VS.NET 2002 on Windows 2000 successfully. I know that in order to debug a stored procedure, I need to enable SQLServer debugging for my solution and the option for this is located via Solution-Properties - Configuration properties - Debugging. Recently I am working on a Windows 2003 machine that has VS.net 2003 enterprise architect edition installed, and I am not being able...
0
3153
by: DR | last post by:
Unable to start TSQL Debugging. Could not attach to SQL Server Process on 'srvname'. The RPC server is unavailable. I get this error when I try to run a SQL Server Project with a CLR stored Procedure in it. The target DB is SQL Server 2005 and im using VS 2005. I simply create a new SQL Server Project which creates a Test.sql, i then simply added a Stored Procedure to it called the default name StoredProcedure1.cs and put a break point...
1
5993
by: okonita | last post by:
Hello all, I have a Java problem that I hope can be answered here. Very new to DB2 UDB and UDF (we are on DB2v9.5, Linux and Windows), I have managed to get the UDF registered but having problem getting the Java code to work. I need assistance to get this Double Metaphone Java UDF to work pretty quickly. Here is what I tried to run and the error message that resulted: SQL select nm_frst, NM_LST,...
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9280
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6016
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.