Using an existing JDBC Connection
Using an existing JDBC Connection
am 09.08.2007 17:57:53 von Mathew.Delong
------_=_NextPart_001_01C7DA9E.0B438E34
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="us-ascii"
I am calling into a Perl script from a Java class to retrieve
information from a database, and am interested in using DBI for the
connection. However, the Java class calling into the perl script will
already have an established JDBC connection to the database, and I would
like to reuse this connection instead of creating a second connection.
Is there any way to do this with DBI, or am I barking up the wrong tree?
=20
Thanks,
=20
Mathew DeLong
Software Developer, Toronto
[Embarcadero Technologies Logo] =20
Embarcadero Technologies, Inc. | www.embarcadero.com
=20
110 Spadina Avenue, Suite 400 | Toronto, ON, M5V 2K4, Canada
mathew.delong@embarcadero.com =20
Office: 416-593-1585 x253 | Fax: 416-593-4328 | Cell: 647-241-2727=20
=20
CONFIDENTIALITY NOTICE: This email message is for the sole use of the inten=
ded recipient(s)=20
and may contain confidential and privileged information. Any unauthorized r=
eview, use,=20
disclosure or distribution is prohibited. If you are not the intended recip=
ient, please=20
contact the sender by reply email and destroy all copies of the original me=
ssage.
------_=_NextPart_001_01C7DA9E.0B438E34--
Re: Using an existing JDBC Connection
am 09.08.2007 18:07:23 von jonathan.leffler
On 8/9/07, Mathew Delong wrote:
> I am calling into a Perl script from a Java class to retrieve
> information from a database, and am interested in using DBI for the
> connection. However, the Java class calling into the perl script will
> already have an established JDBC connection to the database, and I would
> like to reuse this connection instead of creating a second connection.
> Is there any way to do this with DBI, or am I barking up the wrong tree?
You're barking up the wrong tree, IMNSHO.
In general, separate processes cannot share a single database
connection. It is doubly complicated when the processes use different
language infrastructures (Java and Perl in your case).
I wouldn't go so far as to say "it can never, ever be done". But I
wouldn't want to go to the effort of making it work - it would be
excruciatingly hard and revoltingly error prone and most probably
wholly unportable (across platforms and across DBMS)..
--
Jonathan Leffler #include
Guardian of DBD::Informix - v2007.0226 - http://dbi.perl.org
"Blessed are we who can laugh at ourselves, for we shall never cease
to be amused."
Re: Using an existing JDBC Connection
am 09.08.2007 18:37:57 von hjp
--C+ts3FVlLX8+P6JN
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On 2007-08-09 11:57:53 -0400, Mathew Delong wrote:
> I am calling into a Perl script from a Java class to retrieve
> information from a database, and am interested in using DBI for the
> connection. However, the Java class calling into the perl script will
> already have an established JDBC connection to the database, and I would
> like to reuse this connection instead of creating a second connection.
Generally this is not possible. Your perl script will be executed by a
second process and most databases don't support sharing database
connections between processes (It's too difficult to keep the processess
=66rom messing with each other). Even if your database does support it, it
is unlikely that the JDBC driver and the DBD driver also support it in
a compatible way, so I wouldn't bother and just open a new connection.
hp
--=20
_ | Peter J. Holzer | If I wanted to be "academically correct",
|_|_) | Sysadmin WSR | I'd be programming in Java.
| | | hjp@wsr.ac.at | I don't, and I'm not.
__/ | http://www.hjp.at/ | -- Jesse Erlbaum on dbi-users
--C+ts3FVlLX8+P6JN
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFGu0LlMdFfQa64PCwRAsYFAKCSq1cP2dm7yU+cof878Idhj6fmawCe NsoS
a4/4DomIWPeRuqo25G1+Vvg=
=7+Jb
-----END PGP SIGNATURE-----
--C+ts3FVlLX8+P6JN--
RE: Using an existing JDBC Connection
am 09.08.2007 22:12:48 von Mathew.Delong
The issue is that I want to keep the connections on the database to a
minimum (1 if possible,) to avoid any problems which might come up with
a maximum number of connections be allowed at any given time.
I was thinking there might be some java library out there which will
basically wrap a JDBC connection and at the same time act as the
connection retrieved from DBI for the Perl script. So the script thinks
it is dealing with one connection when it is actually delegating into
the original one.
-----Original Message-----
From: Peter J. Holzer [mailto:hjp@wsr.ac.at]=20
Sent: Thursday, August 09, 2007 12:38 PM
To: dbi-users@perl.org
Subject: Re: Using an existing JDBC Connection
On 2007-08-09 11:57:53 -0400, Mathew Delong wrote:
> I am calling into a Perl script from a Java class to retrieve
> information from a database, and am interested in using DBI for the
> connection. However, the Java class calling into the perl script will
> already have an established JDBC connection to the database, and I
would
> like to reuse this connection instead of creating a second connection.
Generally this is not possible. Your perl script will be executed by a
second process and most databases don't support sharing database
connections between processes (It's too difficult to keep the processess
from messing with each other). Even if your database does support it, it
is unlikely that the JDBC driver and the DBD driver also support it in
a compatible way, so I wouldn't bother and just open a new connection.
hp
--=20
_ | Peter J. Holzer | If I wanted to be "academically correct",
|_|_) | Sysadmin WSR | I'd be programming in Java.
| | | hjp@wsr.ac.at | I don't, and I'm not.
__/ | http://www.hjp.at/ | -- Jesse Erlbaum on dbi-users
CONFIDENTIALITY NOTICE: This email message is for the sole use of the inten=
ded recipient(s)=20
and may contain confidential and privileged information. Any unauthorized r=
eview, use,=20
disclosure or distribution is prohibited. If you are not the intended recip=
ient, please=20
contact the sender by reply email and destroy all copies of the original me=
ssage.
Re: Using an existing JDBC Connection
am 09.08.2007 22:16:57 von jonathan.leffler
On 8/9/07, Mathew Delong wrote:
> The issue is that I want to keep the connections on the database to a
> minimum (1 if possible,) to avoid any problems which might come up with
> a maximum number of connections be allowed at any given time.
Nice target. Not attainable.
> I was thinking there might be some java library out there which will
> basically wrap a JDBC connection and at the same time act as the
> connection retrieved from DBI for the Perl script. So the script thinks
> it is dealing with one connection when it is actually delegating into
> the original one.
Nope. Nothing doing.
> -----Original Message-----
> From: Peter J. Holzer [mailto:hjp@wsr.ac.at]
> Sent: Thursday, August 09, 2007 12:38 PM
> To: dbi-users@perl.org
> Subject: Re: Using an existing JDBC Connection
>
> On 2007-08-09 11:57:53 -0400, Mathew Delong wrote:
> > I am calling into a Perl script from a Java class to retrieve
> > information from a database, and am interested in using DBI for the
> > connection. However, the Java class calling into the perl script will
> > already have an established JDBC connection to the database, and I would
> > like to reuse this connection instead of creating a second connection.
>
> Generally this is not possible. Your perl script will be executed by a
> second process and most databases don't support sharing database
> connections between processes (It's too difficult to keep the processess
> from messing with each other). Even if your database does support it, it
> is unlikely that the JDBC driver and the DBD driver also support it in
> a compatible way, so I wouldn't bother and just open a new connection.
--
Jonathan Leffler #include
Guardian of DBD::Informix - v2007.0226 - http://dbi.perl.org
"Blessed are we who can laugh at ourselves, for we shall never cease
to be amused."
Re: Using an existing JDBC Connection
am 09.08.2007 23:13:34 von rvtol+news
"Mathew Delong" schreef:
> I am calling into a Perl script from a Java class to retrieve
> information from a database, and am interested in using DBI for the
> connection. However, the Java class calling into the perl script will
> already have an established JDBC connection to the database, and I
> would
> like to reuse this connection instead of creating a second connection.
> Is there any way to do this with DBI, or am I barking up the wrong
> tree?
Put some proxy-daemon in between? Only the proxy connects to the
database, both the "Java class" and the "Perl script" connect to the
proxy.
--
Affijn, Ruud
"Gewoon is een tijger."
Re: Using an existing JDBC Connection
am 10.08.2007 10:16:04 von hjp
--/WwmFnJnmDyWGHa4
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On 2007-08-09 16:12:48 -0400, Mathew Delong wrote:
> The issue is that I want to keep the connections on the database to a
> minimum (1 if possible,) to avoid any problems which might come up with
> a maximum number of connections be allowed at any given time.
>=20
> I was thinking there might be some java library out there which will
> basically wrap a JDBC connection and at the same time act as the
> connection retrieved from DBI for the Perl script. So the script thinks
> it is dealing with one connection when it is actually delegating into
> the original one.
I was googling around a bit and stumbled upon the readme of DBD::JDBC:
| This module also allows a Java application or servlet to create
| a JDBC connection and then exec a Perl script which can use
| that pre-existing JDBC connection via DBI.=20
Looks like that is what you need.
hp
--=20
_ | Peter J. Holzer | If I wanted to be "academically correct",
|_|_) | Sysadmin WSR | I'd be programming in Java.
| | | hjp@wsr.ac.at | I don't, and I'm not.
__/ | http://www.hjp.at/ | -- Jesse Erlbaum on dbi-users
--/WwmFnJnmDyWGHa4
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFGvB7EMdFfQa64PCwRAgyoAKCKi9sohaMO5v+q6N+ii/Nkc9rThwCg gB3W
51IsprSpeF8nvqs5nx32gnw=
=vCyM
-----END PGP SIGNATURE-----
--/WwmFnJnmDyWGHa4--