[armedbear-devel] Connection to database via JDBC and classpath

Francisco Vides Fernández fvides at dedaloingenieros.com
Fri May 18 09:20:38 UTC 2012

El 18/05/12 00:21, Alessio Stalla escribió:
> On Thu, May 17, 2012 at 11:04 PM, Francisco Vides Fernández
> <fvides at igaleno.com> wrote:
>> Hello everyone
>> 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]
>> -------8<-------
>> The jar file exists, and has the proper class inside. I've read the manual,
>> and googled a bit, but still get the same error. I'm using Ubuntu Linux,
>> with OpenJDK 1.6.0_24, and the latest and greatest ABCL downloaded as a
>> binary from ABCL website. Can someone point me what I'm doing wrong?
> TL;DR: use (java:jclass "org.postgresql.Driver").

Yes, that did the trick, but now I've the following code:
(java:jclass "org.postgresql.Driver")
#<java.lang.Class class org.postgresql.Driver {67AFF9E8}>
;; the driver loads, yay!

(java:jstatic "getConnection" "java.sql.DriverManager"

Java exception 'java.sql.SQLException: No suitable driver found for
   [Condition of type JAVA-EXCEPTION]

But the equivalent java code works:
public class JdbcConn
   public static void main(String[] args)
     java.sql.Connection c =
      catch(Exception e)

I fail to see how the ClassLoader machinery affects this. The
org.postgresql.Driver class self-registers with driver manager, in a
static block of code:

java.sql.DriverManager.registerDriver(new Driver());

But apparently that isn't happening. I've even tried to do that by hand
but nothing.

Some clue on what's happening?

| Francisco Vides Fernández <fvides at igaleno.com>
| Gerente
| Teléfono fijo:   952 60 29 59
| Fax:             952 60 29 59
| igaleno http://www.igaleno.com/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/armedbear-devel/attachments/20120518/92cf9f77/attachment.html>

More information about the armedbear-devel mailing list