On Sun, Jan 8, 2012 at 8:26 PM, jayvandal <s...@ida.net> wrote:
> I have been able to access tables in mysql, but not able to add
> records. I look at the examples fo "fruit  so I created a lein named
> fruitI made th project file as the mysql project file. I copied the
> database instructions as in mysql. I added all of the statements for
> the "fruit" example but I can't even get it to access the connection
> or the database

You must provide more detail when asking questions: what is the exact
error message / problem you see? How exactly are you running your code
(you never answer this one)?

> Here is  the project file ;
> defproject fruit "1.0.0-SNAPSHOT"
>  :description "FIXME: write description"
>  :dependencies [[org.clojure/clojure "1.3.0"]]
>
>
>                 [org.clojure/java.jdbc "0.0.6"]
>                 [mysql/mysql-connector-java "5.1.6"])

I assume you haven't pasted this correctly?

There was no ( before defproject and you close the dependencies on
line 3 so java.jdbc and mysql-connector-java are not part of that
list. Here's what it should look like:

(defproject fruit "1.0.0-SNAPSHOT"
  :description "FIXME: write description"
  :dependencies [[org.clojure/clojure "1.3.0"]
                 [org.clojure/java.jdbc "0.0.6"]
                 [mysql/mysql-connector-java "5.1.6"]])

> (defn db {:classname "com.mysql.jdbc.Driver"
>         :subprotocol "mysql"
>         :subname "//localhost:3306/world"
>         :user "root"
>         :password "pass"})

This should be a def not a defn.

> (defn create-fruit []
> (sql/with-connection db
>   (sql/create-table
>    :fruit
>    [:id :integer "PRIMARY KEY" "AUTO_INCREMENT"]
>    [:name "varchar(25)"]
>    [:appearance "varchar(25)"]
>        [:cost "integer(5)"]))

You're missing a closing parenthesis here.

> (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]))

This doesn't match how you declared the table: you declared ID
(integer), NAME (varchar), APPEARANCE (varchar), COST (integer) but
you are trying to insert string, string, integer, double.

The http://clojure.github.com/java.jdbc documentation is correct but
you have changed the code to something that does not work.
-- 
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

Reply via email to