add records in mysql????

34 views
Skip to first unread message

jayvandal

unread,
Jan 6, 2012, 3:13:53 PM1/6/12
to Clojure
i am using leinningen and mysql example. I can select records as:

(defn list-ausers []
(sql/with-connection db
(sql/with-query-results rows

["SELECT * FROM books WHERE BOOK_ID = '1'"]
(println rows))))

but I can't insert records,i doesn't like the query as:

(defn add-ausers []
(sql/with-connection db
;(sql/with-query-results rows

sql ["INSERT INTO books(BOOK_ID, BOOK_NAME, BOOK_PRICE,
BOOK_AUTHOR) VALUES('2','joe','12', 'siley')"]
(println rows)

why or?
;)
))

Allen Johnson

unread,
Jan 6, 2012, 3:20:49 PM1/6/12
to clo...@googlegroups.com
You'd want to use one of the insert functions for that:

(defn add-user [user]
(sql/with-connection db
(sql/insert-record :books user)))

http://clojure.github.com/java.jdbc

Allen

> --
> 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

jayvandal

unread,
Jan 6, 2012, 4:56:58 PM1/6/12
to Clojure
I tried this code :
(defn add-ausers [user]
(sql/with-connection db
(sql/insert-record :books user
["INSERT INTO books(BOOK_ID, BOOK_NAME, BOOK_PRICE, BOOK_AUTHOR)
VALUES('%','joe','12', 'siley')"];

(println rows))))

user=> (mysql.core/add-ausers)
java.sql.SQLException: Can not issue data manipulation statements with
executeQu
ery(). (NO_SOURCE_FILE:0)

What is Query??
> > Groups "Clojure" group.> To post to this group, send email tocl...@googlegroups.com

jayvandal

unread,
Jan 6, 2012, 4:58:22 PM1/6/12
to Clojure

Sean Corfield

unread,
Jan 7, 2012, 7:17:44 PM1/7/12
to clo...@googlegroups.com
Documentation:

http://clojure.github.com/java.jdbc/doc/clojure/java/jdbc/UsingSQL.html
> 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 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)

Henrik Lundahl

unread,
Jan 6, 2012, 5:30:20 PM1/6/12
to clo...@googlegroups.com
Hi

You're not supposed to specify the insert statement. Try this:

(sql/insert-record :books
  {:BOOK_ID "%", :BOOK_NAME "joe", :BOOK_PRICE 12, :BOOK_AUTHOR "siley"})

...using the same values as in your insert statement. Don't know about BOOK_ID, though...


--
Henrik



To post to this group, send email to clo...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages