MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Packages--JLink class is loaded but cannot be found?

  • To: mathgroup at
  • Subject: [mg66582] Re: [mg66548] Packages--JLink class is loaded but cannot be found?
  • From: Todd Gayley <tgayley at>
  • Date: Sat, 20 May 2006 04:48:28 -0400 (EDT)
  • Sender: owner-wri-mathgroup at


First off, I want to point out that people who have Mathematica 5.1 and 
later have the DatabaseLink application, which is what one would use to 
interact with Oracle or other databases. You have Mathematica 5.0, so you 
are stuck with using "raw" J/Link as in Brian's JDBC example code.

The problem you are having is a subtle classloading problem. The JDBC 
DriverManager uses a rather unfortunate scheme for locating driver classes. 
The DriverManager only sees classes that are loaded by the same classloader 
that loaded the DriverManager class itself. When using J/Link, the 
DriverManager class is loaded by the system classloader (because it is a 
built-in part of Java), but the driver class is loaded by the 
JLinkClassLoader (because it is found via the classpath). Although there is 
another way around this, an easy thing to do is to put the ojdbc14.jar file 
into the Java runtime's "extensions" directory, which is <mathematica 
dir>/SystemFiles/Java/Windows/lib/ext. Then it will be found by the 
DriverManager and you won't need to use AddToClassPath or any other 
classpath-related tweaks.

One final thing. Whenever you type a string literal in Mathematica (just as 
in C, Java, etc.), you have to use double backslashes, as a single 
backslash is an escape character:


Todd Gayley
Wolfram Research

At 02:40 AM 5/19/2006, wbogorad at wrote:
>I'm very new to Mathematica and JLink but I know a thing or two about 
>Java. I'm using Mathematica 5.0 and I'm trying to follow Brian Higgins' 
>example ( to 
>connect to Oracle (not MySQL database and I'm having a strange problem 
>that the system seems is loading oracle jdbc driver but than cannot see it.
>Here how I do it
>InstallJava[]; \
>--- at this point the system seems to be happy with  the classpath: 
>{C:\Program Files\WolframResearch\Mathematica\5.0\SystemFiles\Java\, \
>C:\Program Files\WolframResearch\Mathematica\5.0\.\, \
>c:\oracle\product\9.2\db_1\jdbc\lib\ojdbc14.jar, C:\Program \
>myDriverManager = LoadJavaClass["java.sql.DriverManager"]
>myClass = LoadJavaClass["java.lang.Class"]
>cls = JLinkClassLoader`classFromName["oracle.jdbc.driver.OracleDriver"]
>-- the output is: «JavaObject[oracle.jdbc.driver.OracleDriver]» so it 
>seems that the driver instance is created.
>myDriverList = java`sql`DriverManager`getDrivers[]
>s = {};
>While[myDriverList[hasMoreElements[]], AppendTo[s, \
>-- but when I try to get a list of loaded drivers the list is empty; the 
>output is: {}
>My question is what have I done wrong?

  • Prev by Date: Re: (Newbie question): New types of numbers
  • Next by Date: Re: Reconstructing data points from a InterpolatingFunction object
  • Previous by thread: Packages--JLink class is loaded but cannot be found?
  • Next by thread: Exporting Graphics to .eps