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 ...");
}
}
for multiple vectors, the function is varargs:
If you want to generate the input from a list, you can use apply:
For a literal reproduction of that logic, you cannot use the varargs, because it does not give you a chance to check each return value before the next operation: