I guess I cange some things ecauseI don't know what the commands actually
do.
Icopied some ccode fromNakkaya "using mysql with clojure and for some reason
I go that code running. I got to study what I screwed up in your fruit code
and seeif I can understand that.
Thanks
----- Original Message -----
From: "Sean Corfield" <seancorfi...@gmail.com>
To: <clojure@googlegroups.com>
Sent: Monday, January 09, 2012 9:06 PM
Subject: Re: mysql and fruit tables
On Mon, Jan 9, 2012 at 3:43 PM, <s...@ida.net> wrote:
I run lein repl
I enter statement"(load "/fruit/core")
You can just do:
(require 'fruit.core)
I enter statement "(fruit.core/create-fruit)
I get error message
==============================
user=> (fruit.core/insert-rows-fruit)
Exception no current database connection
clojure.java.jdbc.internal/connection*
(internal.clj:40)
Your original insert-rows-fruit looked like this:
(defn insert-rows-fruit
"Insert complete rows"
[]
(sql/insert-rows
:fruit
["Apple" "red" 59 87]
["Banana" "yellow" 29 92.2]
["Peach" "fuzzy" 139 90.0]
["Orange" "juicy" 89 88.6]))
It doesn't have a with-connection call.
In your latest email, you have:
(defn insert-rows-fruit
(sql/with-connection db
"Insert complete rows"
[]
(sql/insert-record :books
(sql/insert-rows
:fruit
["Apple" "red" 59 87]
["Banana" "yellow" 29 92.2]
["Peach" "fuzzy" 139 90.0]
["Orange" "juicy" 89 88.6]))
This cannot be what your actual code looks like - the parentheses
don't match and your function has no argument list (because you've
wrapped the with-connection call around too much - and you have both
an insert-record and an insert-rows call in there).
Your choices are either to type this in the REPL:
user=> (require '[clojure.java.jdbc :as sql])
nil
user=> (sql/with-connection fruit.core/db (fruit.core/insert-rows-fruit))
BatchUpdateException Incorrect integer value: 'Orange' for column 'id'
at row 1 com.mysql.jdbc.PreparedStatement.executeBatchSerially
(PreparedStatement.java:1666)
user=>
(I pointed out you'd get that exception because you changed the table
definition from what works in the documentation to something else and
you're inserting incompatible data - see my previous response)
or update your insert-rows-fruit function like this:
(defn insert-rows-fruit
"Insert complete rows"
[]
(sql/with-connection db
(sql/insert-rows
:fruit
["Apple" "red" 59 87]
["Banana" "yellow" 29 92.2]
["Peach" "fuzzy" 139 90.0]
["Orange" "juicy" 89 88.6])))
That will solve the connection problem. Of course, you're still get
the BatchUpdateException - see above.
I'm not sure what you mean by
How exactly are you running your code
(you never answer this one)?
You've finally answered this by showing the commands you type in the
REPL. There are lots of ways to run Clojure code - I needed to see how
you were running your code to be able to reproduce your problems and
suggest fixes.
--
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)
--
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
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--
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
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en