[armedbear-devel] Connection to database via JDBC and classpath
Mark Evenson
evenson at panix.com
Fri May 18 11:06:52 UTC 2012
On 5/18/12 12:14 , Alessio Stalla wrote:
> On Fri, May 18, 2012 at 11:20 AM, Francisco Vides Fernández
>
[…]
>> I intend to use ABCL in one of my projects. I've started to connectiing to a
>> postgresq database via jdbc. I've tried something like:
>>
>> -------8<-------
>> (add-to-classpath
>> (merge-pathnames
>> #p".m2/repository/postgresql/postgresql/8.4-702.jdbc4/postgresql-8.4-702.jdbc4.jar"
>> (user-homedir-pathname)))
>>
>> (jstatic "forName" "java.lang.Class" "org.postgresql.Driver")
>> -------8<-------
>>
>> But it always returns
>> -------8<-------
>> Java exception 'java.lang.ClassNotFoundException: org.postgresql.Driver'.
>> [Condition of type JAVA-EXCEPTION]
> Or you can revert to Class.forName, but ensuring to use the overload
> that takes an explicit classloader, and feeding it the one used by
> ABCL (look in java.lisp to see how to retrieve it).
>
> On the long term, though, jclass really needs to take an extra
> argument to force initialization.
[…]
One might try using the JSS:NEW operator which has a slightly more
aggressive method of locating Java classes with the
[java.sql.DriverManager API][1], which is the preferred way of loading
JDBC drivers rather than the Class.forName() method.
[1]: http://docs.oracle.com/javase/6/docs/api/java/sql/DriverManager.html
For loading Oracle drivers, the following code works for me. I would
expect that it would for Postgres as well with suitable modification of
the parameters.
(require 'abcl-contrib)
(require 'abcl-asdf)
(require 'jss)
(defparameter *driver-pathname*
"~/dist/ojdbc6.jar")
(defparameter *driver-class*
"oracle.jdbc.OracleDriver")
(defun ensure-driver ()
(java:add-to-classpath *driver-pathname*)
(#"registerDriver" 'java.sql.DriverManager (new *driver-class*)))
--
"A screaming comes across the sky. It has happened before, but there
is nothing to compare to it now."
More information about the armedbear-devel
mailing list