This is a multi-part message in MIME format.
------=_NextPart_000_0018_01C8B0FE.6D5025D0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Cool, thanks.
> The only problem is then doing the connection as the DriverManager =
will refuse to use a driver that was loaded by a different classloader.
While I was awaiting your reply, I thought I would have a go at it =
myself. For what it is worth, the following also works. So the "standard =
method" of connecting to a database (via DriverManager) seems to work =
now (at least for my JDBC driver).
As mentioned I'm working in Java 6.0.
// For some reason my driver is in three parts
URL jdbc1 =3D new URL =
("file:/classpath/jars/JDBC/tdgssconfig.jar");
URL jdbc2 =3D new URL =
("file:/classpath/jars/JDBC/tdgssjava.jar");
URL jdbc3 =3D new URL =
("file:/classpath/jars/JDBC/terajdbc4.jar");
=20
// Either of the following seem to work.
// ClassLoader loader =3D new URLClassLoader (new URL [] { =
path, jdbc1, jdbc2, jdbc3 }, this.getClass().getClassLoader());
ClassLoader loader =3D new URLClassLoader (new URL [] { =
path, jdbc1, jdbc2, jdbc3 });
Class jdbcClass =3D loader.loadClass =
("com.ncr.teradata.TeraDriver");
// The following is required otherwise I =
get a "No suitable driver" SQLException.
Object jdbcDriver =3D jdbcClass.newInstance ();
Connection c =3D =
DriverManager.getConnection("jdbc:teradata://dbc/", "uid", "pass");
Statement s =3D c.createStatement();
ResultSet r =3D s.executeQuery("select * from t1;");
while (r.next()) {
System.out.println (r.getString(1) + ", " + r.getString =
(2));
}
r.close ();
s.close ();
c.close ();
Thanks again for your post Thomas, it really helped point me in the =
right direction.
Glenn Mc
"Thomas Kellerer" <YQDHXVLMUBXG@[EMAIL PROTECTED]
> wrote in message =
news:68dkudF2sv349U1@[EMAIL PROTECTED]
> Sorry, I meant Driver.connect()
>=20
> Once you have loaded the driver class using a URLClassLoader, you can =
create a new instance and cast that to a Driver and then ask the driver =
to connect.
>=20
> Something like this:
>=20
> URLClassLoader l =3D new URLClassLoader(...);
> Class drvClass =3D l.loadClass("org.postgresql.Driver");
> java.sql.Driver drv =3D (java.sql.Driver)drvClass.newInstance();
> Properties props =3D new Properties();
> props.put("user", "postgres");
> props.put("password", "password");
>=20
> java.sql.Connection conn =3D =
drv.connect("jdbc:postgresql:localhost/mydb", props);
>=20
> Regards
> Thomas
>=20
>=20
>=20
------=_NextPart_000_0018_01C8B0FE.6D5025D0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.6000.16643" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Cool, thanks.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>> <FONT face=3D"Times New Roman" =
size=3D3>The only=20
problem is then doing the connection as the DriverManager will refuse to =
use a=20
driver that was loaded by a different =
classloader.</FONT><BR></DIV></FONT>
<DIV><FONT face=3DArial size=3D2>While I was awaiting your reply, I =
thought I would=20
have a go at it myself. For what it is worth, the following also works. =
So the=20
"standard method" of connecting to a database (via DriverManager) seems =
to work=20
now (at least for my JDBC driver).</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>As mentioned I'm working in Java =
6.0.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New"=20
size=3D2> &nbs=
p; =20
// For some reason my driver is in three parts</FONT></DIV>
<DIV><FONT face=3D"Courier New"=20
size=3D2> &nbs=
p; URL=20
jdbc1 =3D new URL=20
("file:/classpath/jars/JDBC/tdgssconfig.jar");<BR>  =
; =20
URL jdbc2 =3D new URL=20
("file:/classpath/jars/JDBC/tdgssjava.jar");<BR> &=
nbsp; =20
URL jdbc3 =3D new URL=20
("file:/classpath/jars/JDBC/terajdbc4.jar");<BR> &=
nbsp; =20
</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2> =
=20
=
=20
// Either of the following seem to=20
work.<BR>// &n=
bsp;=20
ClassLoader loader =3D new URLClassLoader (new URL [] { path, jdbc1, =
jdbc2, jdbc3=20
},=20
this.getClass().getClassLoader());<BR>  =
; =20
ClassLoader loader =3D new URLClassLoader (new URL [] { path, jdbc1, =
jdbc2, jdbc3=20
});<BR><BR> &n=
bsp;=20
Class jdbcClass =3D loader.loadClass =
("com.ncr.teradata.TeraDriver");</FONT></DIV>
<DIV><FONT face=3D"Courier New"=20
size=3D2> &nbs=
p;  =
; =20
// The following is required otherwise I get a "No suitable=20
driver" SQLException.</FONT><FONT face=3D"Courier New"=20
size=3D2><BR> =
=20
Object jdbcDriver =3D jdbcClass.newInstance=20
();<BR><BR> &n=
bsp;=20
Connection c =3D DriverManager.getConnection("jdbc:teradata://dbc/", =
"uid",=20
"pass");<BR> &=
nbsp;=20
Statement s =3D=20
c.createStatement();<BR> &=
nbsp; =20
ResultSet r =3D s.executeQuery("select * from=20
t1;");<BR> &nb=
sp;=20
while (r.next())=20
{<BR> &n=
bsp; =20
System.out.println (r.getString(1) + ", " + r.getString=20
(2));<BR> &nbs=
p;=20
}<BR> =
r.close=20
();<BR> =
=20
s.close=20
();<BR> =
=20
c.close ();<BR><BR><FONT face=3DArial>Thanks again for your post Thomas, =
it really=20
helped point me in the right direction.</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DArial></FONT></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT face=3DArial>Glenn=20
Mc</FONT></DIV></FONT>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>"Thomas Kellerer" <</FONT><A=20
href=3D"mailto:YQDHXVLMUBXG@[EMAIL PROTECTED]
"><FONT face=3DArial=20
size=3D2>YQDHXVLMUBXG@[EMAIL PROTECTED]
></A><FONT face=3DArial =
size=3D2>> wrote=20
in message </FONT><A =
href=3D"news:68dkudF2sv349U1@[EMAIL PROTECTED]
"><FONT=20
face=3DArial =
size=3D2>news:68dkudF2sv349U1@[EMAIL PROTECTED]
></A><FONT=20
face=3DArial size=3D2>...</FONT></DIV><FONT face=3DArial size=3D2>> =
Sorry, I meant=20
Driver.connect()<BR>> <BR>> Once you have loaded the driver class =
using a=20
URLClassLoader, you can create a new instance and cast that to a Driver =
and then=20
ask the driver to connect.<BR>> <BR>> Something like this:<BR>> =
<BR>> URLClassLoader l =3D new URLClassLoader(...);<BR>> Class =
drvClass =3D=20
l.loadClass("org.postgresql.Driver");<BR>> java.sql.Driver drv =3D=20
(java.sql.Driver)drvClass.newInstance();<BR>> Properties props =3D =
new=20
Properties();<BR>> props.put("user", "postgres");<BR>>=20
props.put("password", "password");<BR>> <BR>> java.sql.Connection =
conn =3D=20
drv.connect("jdbc:postgresql:localhost/mydb", props);<BR>> <BR>>=20
Regards<BR>> Thomas<BR>> <BR>> <BR>> =
<BR></FONT></BODY></HTML>
------=_NextPart_000_0018_01C8B0FE.6D5025D0--


|