I found a workaround...

I was able to register the driver using
-Djdbc.drivers=com.mysql.jdbc.Driver on the java command line.
Looks like loading the class is not enough, adding the above does work:

user=> (enumeration-seq (. java.sql.DriverManager getDrivers))
([EMAIL PROTECTED] [EMAIL PROTECTED])

The mysql jdbc driver code says that it registers itself (static block)
but something is wrong.
Eventually I will find why but now I have other pressing needs to full
fill than debugging that code.

The following fails:

user=>  (cast java.sql.Driver (clojure.lang.RT/classForName
"com.mysql.jdbc.Driver"))
java.lang.ClassCastException (NO_SOURCE_FILE:0)

The com.mysql.jdbc.Drive does implement the java.sql.Driver interface:

user=> (bases  (clojure.lang.RT/classForName "com.mysql.jdbc.Driver"))
(com.mysql.jdbc.NonRegisteringDriver java.sql.Driver)

Is my syntax right ? Does the cast function checks only the class and
its ancestors and not interfaces ?
Does it require a class object ? I tried this:

(cast  (clojure.lang.RT/classForName "java.sql.Driver") (.
java.sql.DriverManager getDrivers))
java.lang.ClassCastException (NO_SOURCE_FILE:0)

I would like to force the registering of the driver myself at startup
avoiding the whole issue.

Any ideas ? Sorry for what may seem "basic" questions...

Thanks Luc

On Thu, 2008-10-09 at 13:03 -0400, Stephen C. Gilardi wrote:

> 
> 
> On Oct 9, 2008, at 12:06 PM, Luc Prefontaine wrote:
> 
> 
> 
> > Hi everyone, 
> > 
> > I may look stupid but how do you cast Java arguments ?
> > 
> > (java.sql.DriverManager/registerDriver (clojure.lang.RT/classForName
> > "com.mysql.jdbc.Driver"))
> > java.lang.ClassCastException: java.lang.Class cannot be cast to
> > java.sql.Driver (NO_SOURCE_FILE:0)
> > 
> > I fully agree with the error message but how can I change from
> > Object to java.sql.Driver ? I tried half a dozen ways and
> > searched on the web site but nothing yet.
> 
> 
> 
> Hi Luc,
> 
> 
> I haven't used registerDriver. It looks like it's intended to be
> called from within com.mysql.jdbc.Driver to register itself with the
> manager.
> 
> 
> In example code I've seen, a *user* of a jdbc driver (as distinguished
> from a driver implementer) only needs to arrange for the class to be
> loaded with code like:
> 
> 
> (clojure/lang.RT/classForName "com.mysql.jdbc.Driver")
> 
> 
> That has worked for me. You may also find some good info in the source
> code for 'clojure.contrib.sql which includes an example that uses
> derby. Please see:
> 
> 
> http://clojure-contrib.svn.sourceforge.net/viewvc/clojure-contrib/trunk/src/clojure/contrib/sql/sql.clj?revision=190&view=markup
> 
> 
> and
> 
> 
> http://clojure-contrib.svn.sourceforge.net/viewvc/clojure-contrib/trunk/src/clojure/contrib/sql/test/test.clj?revision=190&view=markup
> 
> 
> To answer your casting question, Clojure provides some functions along
> those lines:
> 
> 
>  (find-doc "[Cc]ast|[Cc]oerce")
> 
> 
> Will show you some docs for them.
> 
> 
> --Steve
> 
> 
> 
> 
> > 

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to