<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000099" bgcolor="#FFFFFF">
El 18/05/12 00:21, Alessio Stalla escribió:
<blockquote
cite="mid:CAL2Kp+hk7UN2s8O-O5TN8Euh-xKijoJoVtLf1tVAEiVrr3G9mA@mail.gmail.com"
type="cite">
<pre wrap="">On Thu, May 17, 2012 at 11:04 PM, Francisco Vides Fernández
<a class="moz-txt-link-rfc2396E" href="mailto:fvides@igaleno.com"><fvides@igaleno.com></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">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?
</pre>
</blockquote>
<pre wrap="">
TL;DR: use (java:jclass "org.postgresql.Driver").</pre>
</blockquote>
[snip]<br>
<br>
Yes, that did the trick, but now I've the following code:<br>
--------------8x--------------<br>
(java:jclass "org.postgresql.Driver")<br>
#<java.lang.Class class org.postgresql.Driver {67AFF9E8}><br>
;; the driver loads, yay!<br>
<br>
(java:jstatic "getConnection" "java.sql.DriverManager"
"jdbc:postgresql://localhost:5432/test")<br>
--------------8x--------------<br>
Throws:<br>
<br>
--------------8x--------------<br>
Java exception 'java.sql.SQLException: No suitable driver found for
jdbc:postgresql://localhost:5432/test'.<br>
[Condition of type JAVA-EXCEPTION]<br>
--------------8x--------------<br>
<br>
But the equivalent java code works:<br>
--------------8x--------------<br>
public class JdbcConn<br>
{<br>
public static void main(String[] args)<br>
{<br>
try<br>
{<br>
Class.forName("org.postgresql.Driver");<br>
java.sql.Connection c =
java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/test");<br>
}<br>
catch(Exception e)<br>
{<br>
e.printStackTrace(System.err);<br>
}<br>
}<br>
}<br>
--------------8x--------------<br>
<br>
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:<br>
<br>
--------------8x--------------<br>
java.sql.DriverManager.registerDriver(new Driver());<br>
--------------8x--------------<br>
<br>
But apparently that isn't happening. I've even tried to do that by
hand but nothing.<br>
<br>
Some clue on what's happening?<br>
<pre class="moz-signature" cols="72">--
+-----------------
| Francisco Vides Fernández <a class="moz-txt-link-rfc2396E" href="mailto:fvides@igaleno.com"><fvides@igaleno.com></a>
| Gerente
| Teléfono fijo: 952 60 29 59
| Fax: 952 60 29 59
| igaleno <a class="moz-txt-link-freetext" href="http://www.igaleno.com/">http://www.igaleno.com/</a>
+------
</pre>
</body>
</html>