I think the OP just meant to ask how to do a PreparedStatement batch update 
in clojure.jdbc.

The simplest answer is, just give in multiple parameter vectors to 
db-do-prepared

 (sql/db-do-prepared db
                     "INSERT INTO fruit2 ( name, appearance, cost, grade ) 
VALUES ( ?, ?, ?, ? )"
                     ["banana" "yellow" 1 1.0]
                     ["apple" "green" 2 1.0]
                     ["orange" "orange" 3 1.0])

And as usual, if you have what should be separate parameters already in a 
collection, use the apply function

  (apply sql/db-do-prepared db
  "INSERT INTO fruit2 ( name, appearance, cost, grade ) VALUES ( ?, ?, ?, ? 
)"
   [["banana" "yellow" 1 1.0]
    ["apple" "green" 2 1.0]
    ["orange" "orange" 3 1.0]])

On Sunday, December 8, 2013 11:56:40 PM UTC+1, Sean Corfield wrote:
>
> Do you want that specific piece of (procedural) Java converted to 
> Clojure or do you have a real use case in the context of a real 
> problem that you're trying to solve? 
>
> I suspect just showing you what that piece of Java would look like in 
> Clojure isn't going to teach you how to do this in general... and 
> there are multiple approaches that would each be more suitable to 
> particular real world problems. 
>
> Sean 
>
> On Sun, Dec 8, 2013 at 9:44 AM, Avinash Dongre 
> <dongre....@gmail.com<javascript:>> 
> wrote: 
> > I see following example in Clojure.java.jdbc 
> > 
> > (sql/db-do-prepared db "INSERT INTO fruit2 ( name, appearance, cost, 
> grade ) 
> > VALUES ( ?, ?, ?, ? )" ["test" "test" 1 1.0]) 
> > 
> > But how do i convert following java code into clojure. I am new to 
> clojure 
> > and not sure how to i pass multiple vector 
> > 
> > final int numRows = 10000; 
> >     PreparedStatement pstmt = conn 
> >         .prepareStatement("insert into new_order values (?, ?, ?)"); 
> >     for (int id = 1; id <= numRows; id++) { 
> >       pstmt.setInt(1, id % 98); 
> >       pstmt.setInt(2, id % 98); 
> >       pstmt.setInt(3, id); 
> >       int count; 
> >       if ((count = pstmt.executeUpdate()) != 1) { 
> >         System.err.println("unexpected update count for a single insert 
> " + 
> > count); 
> >         System.exit(2); 
> >       } 
> >       if ((id % 500) == 0) { 
> >         System.out.println("Completed " + id + " inserts ..."); 
> >       } 
> >     } 
> > 
> > -- 
> > -- 
> > 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<javascript:> 
> > 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 <javascript:> 
> > 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 unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to clojure+u...@googlegroups.com <javascript:>. 
> > For more options, visit https://groups.google.com/groups/opt_out. 
>
>
>
> -- 
> 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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to