473,804 Members | 4,128 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQLJ Connection Context and SP interportabilit y

With DB2 7.2 we used to call methods from other SQLJ Stored
Procedures, as it was not possible to call SPs via the SQL
Call-statement from within SPs. So we always had a method like this:

protected static void execute(Connect ion con, (...))

Where we passed a Connection object for dynamic SQL (which we got
using the getConnection() method of the DefaultContext) . Static SQL
was always executed on the DefaultContext.

Now with DB2 8.1 we are forced to create a dedicated Context for each
SP, and therefore changed our execute-method to something like this:

protected static void execute(Connect ionContext context, Connection
con, (...))

The problem now is that the SQLJ Precompiler doesn't like the "simple"
ConnectionConte xt. So if you would try something like this in the
"execute" method

#sql [context] { SELECT imbreqd FROM sysibm.sysdummy 1 }

the precompiler says that you have to declare ConnectionConte xtes
using #sql context declaration. So I changed the execute-method to the
following:

protected static void execute(SPName_ ConnectionConte xt context,
Connection con, (...))

This works fine for the current procedure, but I cannot call the
method from another SP anymore.

There are two solutions which come to mind:
1. Call one SP from another using the SQL-Call-command (now supported
with 8.1)
2. Define one global ConnectionConte xt used by all SPs

The first solution I don't like as it is much slower than calling a
Java method directly. I'm not sure if the second solution is a
"proper" solution, as you always operate on the same context-class and
this may therefore not be threadsafe (I don't know how those
context-classes are implemented).

Maybe somebody can think of another (better) solution or tell me
whether the second solution would be threadsafe or not.

Regards,
- Janick Bernet, SwissASP
Nov 12 '05 #1
9 2989
The reason you need a seperate context in 8.1 is that we're
multithreading on the JVM. Without a context per thread, threads would
run wild over each others objects (cursors etc) closing them, and other
bad things.

If you don't want to use CALL, you can catalog your sqlj stored
procedures as 'not threadsafe' and share the context like you used to
(use the old way of defining the null connection). (I haven't acutally
tried this, but it should work) :-).

You have to choose the tradeoff of multiple JVMs per instance (1 per
concurrently active non threadsafe Java routine) vs. changing your
routines. The change to threadedness was done for scalability.

Janick wrote:
With DB2 7.2 we used to call methods from other SQLJ Stored
Procedures, as it was not possible to call SPs via the SQL
Call-statement from within SPs. So we always had a method like this:

protected static void execute(Connect ion con, (...))

Where we passed a Connection object for dynamic SQL (which we got
using the getConnection() method of the DefaultContext) . Static SQL
was always executed on the DefaultContext.

Now with DB2 8.1 we are forced to create a dedicated Context for each
SP, and therefore changed our execute-method to something like this:

protected static void execute(Connect ionContext context, Connection
con, (...))

The problem now is that the SQLJ Precompiler doesn't like the "simple"
ConnectionConte xt. So if you would try something like this in the
"execute" method

#sql [context] { SELECT imbreqd FROM sysibm.sysdummy 1 }

the precompiler says that you have to declare ConnectionConte xtes
using #sql context declaration. So I changed the execute-method to the
following:

protected static void execute(SPName_ ConnectionConte xt context,
Connection con, (...))

This works fine for the current procedure, but I cannot call the
method from another SP anymore.

There are two solutions which come to mind:
1. Call one SP from another using the SQL-Call-command (now supported
with 8.1)
2. Define one global ConnectionConte xt used by all SPs

The first solution I don't like as it is much slower than calling a
Java method directly. I'm not sure if the second solution is a
"proper" solution, as you always operate on the same context-class and
this may therefore not be threadsafe (I don't know how those
context-classes are implemented).

Maybe somebody can think of another (better) solution or tell me
whether the second solution would be threadsafe or not.

Regards,
- Janick Bernet, SwissASP

Nov 12 '05 #2
The reason you need a seperate context in 8.1 is that we're
multithreading on the JVM. Without a context per thread, threads would
run wild over each others objects (cursors etc) closing them, and other
bad things.

If you don't want to use CALL, you can catalog your sqlj stored
procedures as 'not threadsafe' and share the context like you used to
(use the old way of defining the null connection). (I haven't acutally
tried this, but it should work) :-).

You have to choose the tradeoff of multiple JVMs per instance (1 per
concurrently active non threadsafe Java routine) vs. changing your
routines. The change to threadedness was done for scalability.

Janick wrote:
With DB2 7.2 we used to call methods from other SQLJ Stored
Procedures, as it was not possible to call SPs via the SQL
Call-statement from within SPs. So we always had a method like this:

protected static void execute(Connect ion con, (...))

Where we passed a Connection object for dynamic SQL (which we got
using the getConnection() method of the DefaultContext) . Static SQL
was always executed on the DefaultContext.

Now with DB2 8.1 we are forced to create a dedicated Context for each
SP, and therefore changed our execute-method to something like this:

protected static void execute(Connect ionContext context, Connection
con, (...))

The problem now is that the SQLJ Precompiler doesn't like the "simple"
ConnectionConte xt. So if you would try something like this in the
"execute" method

#sql [context] { SELECT imbreqd FROM sysibm.sysdummy 1 }

the precompiler says that you have to declare ConnectionConte xtes
using #sql context declaration. So I changed the execute-method to the
following:

protected static void execute(SPName_ ConnectionConte xt context,
Connection con, (...))

This works fine for the current procedure, but I cannot call the
method from another SP anymore.

There are two solutions which come to mind:
1. Call one SP from another using the SQL-Call-command (now supported
with 8.1)
2. Define one global ConnectionConte xt used by all SPs

The first solution I don't like as it is much slower than calling a
Java method directly. I'm not sure if the second solution is a
"proper" solution, as you always operate on the same context-class and
this may therefore not be threadsafe (I don't know how those
context-classes are implemented).

Maybe somebody can think of another (better) solution or tell me
whether the second solution would be threadsafe or not.

Regards,
- Janick Bernet, SwissASP

Nov 12 '05 #3
> The reason you need a seperate context in 8.1 is that we're
multithreading on the JVM. Without a context per thread, threads would
run wild over each others objects (cursors etc) closing them, and other
bad things.


My main question regarding this is (which is not answered in then docu
and not apperant in the examples): do you need a seperate context
*class* per procedure or is it enough to have a seperate context
*instances*. I'm afraid its the first one, but I just can't really
imagine why, because thread-safety can easily be achieved on different
instance of the same class.
Anyone has more insight on the db2-sqlj-internals?

Regards
- Janick Bernet, SwissASP
Nov 12 '05 #4
> The reason you need a seperate context in 8.1 is that we're
multithreading on the JVM. Without a context per thread, threads would
run wild over each others objects (cursors etc) closing them, and other
bad things.


My main question regarding this is (which is not answered in then docu
and not apperant in the examples): do you need a seperate context
*class* per procedure or is it enough to have a seperate context
*instances*. I'm afraid its the first one, but I just can't really
imagine why, because thread-safety can easily be achieved on different
instance of the same class.
Anyone has more insight on the db2-sqlj-internals?

Regards
- Janick Bernet, SwissASP
Nov 12 '05 #5
The context as it was created/attained by the SP pre v8 was an SQLJ
static entry (everyone got the same context). If you're running non
threadsafe you can get away with a single instance of this connection
object.

Janick wrote:
The reason you need a seperate context in 8.1 is that we're
multithreadin g on the JVM. Without a context per thread, threads would
run wild over each others objects (cursors etc) closing them, and other
bad things.

My main question regarding this is (which is not answered in then docu
and not apperant in the examples): do you need a seperate context
*class* per procedure or is it enough to have a seperate context
*instances*. I'm afraid its the first one, but I just can't really
imagine why, because thread-safety can easily be achieved on different
instance of the same class.
Anyone has more insight on the db2-sqlj-internals?

Regards
- Janick Bernet, SwissASP

Nov 12 '05 #6
The context as it was created/attained by the SP pre v8 was an SQLJ
static entry (everyone got the same context). If you're running non
threadsafe you can get away with a single instance of this connection
object.

Janick wrote:
The reason you need a seperate context in 8.1 is that we're
multithreadin g on the JVM. Without a context per thread, threads would
run wild over each others objects (cursors etc) closing them, and other
bad things.

My main question regarding this is (which is not answered in then docu
and not apperant in the examples): do you need a seperate context
*class* per procedure or is it enough to have a seperate context
*instances*. I'm afraid its the first one, but I just can't really
imagine why, because thread-safety can easily be achieved on different
instance of the same class.
Anyone has more insight on the db2-sqlj-internals?

Regards
- Janick Bernet, SwissASP

Nov 12 '05 #7
Hmm, Ok. My last chance then to get the thing working threadsafe would
be if the following compiled. Why exactly is that code rejected by the
sqlj-precompiler with the message below?

protected static void execute(Connect ionContext context, Connection
con, (...))
{
#sql [context] { som query };
}

Error: Connection context must have been declared with #sql context
....
It can not be declared as a ConnectionConte xt.

Maybe its possible to get sqlj to ignore this, as the
ConnectionConte xt passed would effectively be a "correct"
ConnectionConte xt declared using "#sql context ...".
Sean McKeough <mc******@nospa m.ca.ibm.com> wrote in message news:<c7******* ***@hanover.tor olab.ibm.com>.. .
The context as it was created/attained by the SP pre v8 was an SQLJ
static entry (everyone got the same context). If you're running non
threadsafe you can get away with a single instance of this connection
object.

Nov 12 '05 #8
Sadly I do not know the inner workings of sqlj well (I only know the
pieces that caused java routines to break once we moved to
threaded)...sor ry. :-(

Janick wrote:
Hmm, Ok. My last chance then to get the thing working threadsafe would
be if the following compiled. Why exactly is that code rejected by the
sqlj-precompiler with the message below?

protected static void execute(Connect ionContext context, Connection
con, (...))
{
#sql [context] { som query };
}

Error: Connection context must have been declared with #sql context
...
It can not be declared as a ConnectionConte xt.

Maybe its possible to get sqlj to ignore this, as the
ConnectionConte xt passed would effectively be a "correct"
ConnectionConte xt declared using "#sql context ...".
Sean McKeough <mc******@nospa m.ca.ibm.com> wrote in message news:<c7******* ***@hanover.tor olab.ibm.com>.. .
The context as it was created/attained by the SP pre v8 was an SQLJ
static entry (everyone got the same context). If you're running non
threadsafe you can get away with a single instance of this connection
object.

Nov 12 '05 #9
Sean McKeough <mc******@nospa m.ca.ibm.com> wrote in message news:<c7******* ***@hanover.tor olab.ibm.com>.. .
Sadly I do not know the inner workings of sqlj well (I only know the
pieces that caused java routines to break once we moved to
threaded)...sor ry. :-(


No Problem, thanks for your help so far.

I decided to do a workaround to achieve what I want. I defined the
method in sqlj as enforced by the precompiler using a dedicated
ConnectionConte xt like this:

#sql context MyProcContext;
...
public static void execute(MyProcC ontext context, ...);
{
#sql context { some query };
}

And then replace MyProcContext with a general ConnectionConte xt in the
java-file generated by the precompiler. This way I can call the
execute() method from other procedures with their corresponding
ConnectionConte xts as parameter.

I still wonder why the sqlj-precompiler doesn't allow we to define a
general ConnectionConte xt to use for executing SQL, as this is
completly legal and doesn't raise an exception if done in the
java-source. In the generated source all contexts are even accessed as
a simple ConnectionConte xt:

sqlj.runtime.Co nnectionContext __sJT_connCtx = context;

Anyway, it works now. Hope it will still work on next Fixpack,
though... ;)
Nov 12 '05 #10

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

Similar topics

2
3520
by: Almund Sebi | last post by:
Hello I have just found this advice on the net: http://www.share.org/proceedings/sh98/data/S1326.PDF I'm interested mainly in page 19: > Use explicit connection context objects > If connection context object is omitted > a default connection context object is used
0
377
by: Janick | last post by:
With DB2 7.2 we used to call methods from other SQLJ Stored Procedures, as it was not possible to call SPs via the SQL Call-statement from within SPs. So we always had a method like this: protected static void execute(Connection con, (...)) Where we passed a Connection object for dynamic SQL (which we got using the getConnection() method of the DefaultContext). Static SQL was always executed on the DefaultContext.
5
5174
by: Raquel | last post by:
This is a very simple DB2 SQLJ stored procedure. The problem is that it seems to run fine but returns NOTHING. I mean..as if nothing has happened..not resultset is returned. I am passing value 'D11' to :workdept and I have checked in the table that 6 rows should have returned. Any ideas why no resultset is being returned. import java.sql.*; import sqlj.runtime.*; import sqlj.runtime.ref.*; import java.io.*; // Input/Output classes
2
1277
by: Jean-Marc Blaise | last post by:
Hi, The Information Center (V8 FP4) states that "Each SQL statement must explicitly indicate the Connection Context object, and that context must be explicitly instantiated in the Java method" to avoid unexpected failures. Can someone give exemples of unexpected failures ? Is it in link with the DB2 Connection Concentrator only ? Thanks for your help,
12
5388
by: Rhino | last post by:
I am having an odd problem: the sqlj command on my system doesn't work. I am running DB2 (LUW) V8 (FP8) on WinXP. I haven't done an sqlj program since Version 6 of DB2 (LUW) so I checked the manuals for the proper techniques to prepare an sqlj program. When I went to try the sqlj command, I got this: Exception in thread "main" java.lang.NoClassDefFoundError: sqlj/tools/Sqlj
2
1808
by: Jean-Marc Blaise | last post by:
Dear all, We try to isolate on Windows 8.2 FP8/FP9 a problem or a bug ? we have on call's on SQLJ procs. Call proc gives SQL0818 indicating a mismatch between the JAR and package (all was done thru Dev Center). Checking syscat.packages gives the same constitency token as a db2sqljprint of the ser file taken out from the JAR. .... strange, isn't it ? No classes or Jar files found on the server.
7
2361
by: Jean-Marc Blaise | last post by:
Hi, The dev center calls sqlj.DB2_UPDATEJARINFO ('JMARC.JMB','JMB','file:JMB.sqlj') to update the sqlj routine source. I tried in CLP from the directory containing jar and sqlj files (Windows 8.2 FP9): db2 connect to sample db2 call sqlj.DB2_UPDATEJARINFO ('JMARC.JMB','JMB','file:JMB.sqlj')
1
3491
by: vasilip | last post by:
I'm trying to insert large polygon data via sql statement. since the data was over 32k I had to use sqlj to insert my data. I made a class that inserts the data. ran sqlj, generated the .java and .ser files then used db2profc to bind the ser file.. not exacly 100% sure what this is about.. but I kind of get the idea.. I imported the java file into my project and attempted to use it..
0
1272
by: ajitkathar | last post by:
In my SQLJ procedure , there is call to another stored procedure using a callable statement. But during excecution when .excute() happens . . the DB2 V7 database shuts down. Plz help. Follwing is the code . . ************ CAL02RSCAL.sqlj which call another PL/SQL Strored procedure TESTRSFILEPL written in DB2 ******************* package PAKCAL02RSCAL ; import java.sql.*;
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
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,...
1
10320
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
10077
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
9150
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
7620
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
6853
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
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.