(:require [clojure.contrib.sql :as sql]))

94 views
Skip to first unread message

jayvandal

unread,
Dec 24, 2011, 1:17:18 AM12/24/11
to Clojure
Where is this file to be found??
(:require [clojure.contrib.sql :as sql]))
I see it listed in the jar but??
I have the clojure.contrib-11.2.0.jar located in my classpath
c:\opt\jars, as well as the clojure.jar

Am I the only one who has trouble with these files??

Sean Corfield

unread,
Dec 24, 2011, 1:43:18 AM12/24/11
to clo...@googlegroups.com
The monolithic contrib (1.2.0) has been deprecated. Updated versions
of many of the modules are available individually:

http://dev.clojure.org/display/design/Where+Did+Clojure.Contrib+Go

However, if you have the JAR on your classpath, that namespace should
be available.

It would help people help you if you provided more detail:
* How are you running your Clojure code?
* What _exact_ error message (and partial stack trace) are you seeing?

Here's an example workflow that shows you can access
clojure.contrib.sql just fine:

sean@sean-netbook:~/clojure$ lein new jay
cd Created new project in: /home/sean/clojure/jay
Look over project.clj and start coding in jay/core.clj
sean@sean-netbook:~/clojure$ cd jay/
sean@sean-netbook:~/clojure/jay$ vi project.clj
sean@sean-netbook:~/clojure/jay$ cat project.clj
(defproject jay "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.2.1"]
[org.clojure/clojure-contrib "1.2.0"]])
sean@sean-netbook:~/clojure/jay$ lein deps
Copying 2 files to /home/sean/clojure/jay/lib
sean@sean-netbook:~/clojure/jay$ lein repl
REPL started; server listening on localhost port 13024
user=> (ns jay.test (:require [clojure.contrib.sql :as sql]))
nil
jay.test=> ^D

Sean

si...@ida.net

unread,
Dec 24, 2011, 4:49:42 PM12/24/11
to clo...@googlegroups.com
I am trying to run clojure file as:
============================================
(ns mysql

(:require [clojure.contrib.sql :as sql]))
:subprotocol "mysql"
:subname "//localhost:3306/dummy"
:user "root"
:password "pass"})
(defn create-users []
(sql/create-table
:users
[:id :integer "PRIMARY KEY" "AUTO_INCREMENT"]
[:fname "varchar(25)"]
[:lname "varchar(25)"]))

(defn drop-users []
(sql/drop-table :users))
(sql/with-connection db
(create-users))
(defn insert-user [fname lname]
(sql/insert-values :users [:fname :lname] [fname lname]))

(sql/with-connection db
(insert-user "Sandy" "Brown"))
(sql/with-connection db
(sql/with-query-results rs ["select * from users"]
(dorun (map #(println %) rs))))

===================================
Do I include this statement to get sql and what is the proper way??


(:require [clojure.contrib.sql :as sql]))

http://dev.clojure.org/display/design/Where+Did+Clojure.Contrib+Go

Sean

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Sean Corfield

unread,
Dec 24, 2011, 6:30:59 PM12/24/11
to clo...@googlegroups.com
On Sat, Dec 24, 2011 at 1:49 PM, <si...@ida.net> wrote:
> I am trying to run clojure file as:
> ============================================
> (ns mysql
>
>  (:require [clojure.contrib.sql :as sql]))

Looks like you're missing a line here before :subprotocol...?

>  :subprotocol "mysql"
>         :subname "//localhost:3306/dummy"
>         :user "root"
>         :password "pass"})
>   (defn create-users []
>  (sql/create-table
>   :users
>   [:id :integer "PRIMARY KEY" "AUTO_INCREMENT"]
>   [:fname "varchar(25)"]
>   [:lname "varchar(25)"]))
>
> (defn drop-users []
>  (sql/drop-table :users))
>  (sql/with-connection db
>  (create-users))
>  (defn insert-user [fname lname]
>  (sql/insert-values :users [:fname :lname] [fname lname]))
>
> (sql/with-connection db
>  (insert-user "Sandy" "Brown"))
>  (sql/with-connection db
>   (sql/with-query-results rs ["select * from users"]
>     (dorun (map #(println %) rs))))
>
> ===================================
> Do I include this statement to get sql and what is the proper way??
>
> (:require [clojure.contrib.sql :as sql]))

You haven't answered the questions about how you are running your
Clojure code (what's on your classpath etc).

Did you try the process I outlined?

> ----- Original Message ----- From: "Sean Corfield" <seanco...@gmail.com>

si...@ida.net

unread,
Dec 24, 2011, 8:27:32 PM12/24/11
to clo...@googlegroups.com
C:\>pathg
'pathg' is not recognized as an internal or external command,
operable program or batch file.

C:\>path
PATH=C:\Perl\site\bin;C:\Perl\bin;C:\Windows\system32;C:\Windows;C:\Windows\Syst
em32\Wbem;C:\hp\bin\Python;c:\Program Files\Common Files\Roxio
Shared\DLLShared\
;c:\Program Files\Common Files\Roxio Shared\9.0\DLLShared\;C:\Program
Files\jZip
;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program
Files\QuickTime\QTSystem
\;c:\lein;c:\cljr\.cljr\bin;c:\opt\;c:\program files\mysql\mysql server
5.5\bin


C:\>set classpath
CLASSPATH=c:/opt/jars/*;c:/projects/clarity4/src

C:\>

--

Sean Corfield

unread,
Dec 24, 2011, 8:59:59 PM12/24/11
to clo...@googlegroups.com
You're still not answering the question of how exactly you are
_running_ your Clojure code.

No one is going to be able to help you if you don't provide enough
details about what _exactly_ you are doing and what error / stack
trace you are getting.

Please also try the command sequence I showed you and see if that works.

jayvandal

unread,
Dec 28, 2011, 12:56:05 AM12/28/11
to Clojure
I have tried the example you provided and it works except I don't see
any file printout of the records when I run not as test but without
test. Is test going to show any data? Can I ask for a record count?
why doesn't the sql jar show for every example that is in the
internet?
Thanks


On Dec 24, 6:59 pm, Sean Corfield <seancorfi...@gmail.com> wrote:
> You're still not answering the question of how exactly you are
> _running_ your Clojure code.
>
> No one is going to be able to help you if you don't provide enough
> details about what _exactly_ you are doing and what error / stack
> trace you are getting.
>
> Please also try the command sequence I showed you and see if that works.
>
>
>
>
>
>
>
> On Sat, Dec 24, 2011 at 5:27 PM,  <s...@ida.net> wrote:
> > C:\>set classpath
> > CLASSPATH=c:/opt/jars/*;c:/projects/clarity4/src
>
> > C:\>
>
> > ----- Original Message ----- From: "Sean Corfield" <seancorfi...@gmail.com>
> > To: <clo...@googlegroups.com>
> > Sent: Saturday, December 24, 2011 4:30 PM
> > Subject: Re: (:require [clojure.contrib.sql :as sql]))
>
> >> <seancorfi...@gmail.com>

Sean Corfield

unread,
Dec 28, 2011, 2:58:30 AM12/28/11
to clo...@googlegroups.com
Sorry, I have no idea what you mean...

jayvandal

unread,
Dec 28, 2011, 10:50:45 AM12/28/11
to Clojure
Doesn't this line of your example run as test?
user=> (ns jay.test (:require [clojure.contrib.sql :as sql]))
=========
The other code I listed was code to run as a clojure program , not as
leiningen, which you said was missing lines of code after the (ns


I apologize for my lack of understanding, but I feel I must be able to
access databases or I can't use clojure

Sean Corfield

unread,
Dec 28, 2011, 3:02:39 PM12/28/11
to clo...@googlegroups.com
On Wed, Dec 28, 2011 at 7:50 AM, jayvandal <si...@ida.net> wrote:
> Doesn't this line of your example  run as test?
> user=> (ns jay.test (:require [clojure.contrib.sql :as sql]))

It's just declaring a namespace and requiring clojure.contrib.sql
(which loads the library). I called it jay.test because it was a test
for Jay :)

> The other code  I listed was code to run as a clojure program , not as
> leiningen, which you said was missing lines of code after the (ns

You have not shown how you actually RUN the code. Since you're not
using Leiningen, I suspect you have a classpath problem but you need
to show us exactly how you are trying to run the code for us to help
debug that.

> I apologize for my lack of understanding, but I feel I must be able to
> access databases or I can't use clojure

I'm sure it's just something simple missing in how you are trying to
run the code. As I've shown, the code itself is likely fine since my
example loads clojure.contrib.sql correctly (because I'm using
Leiningen, the classpath issues are taken care of).
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

Reply all
Reply to author
Forward
0 new messages