Binding Java object to SQL parameters
https://gyazo.com/c5a54e42fa7375ac79471952da4e2314 #Core
Query
For example, in the following select query, Alice is set by PreparedStatement#setString , 30 is set by PreparedStatement#setInt.
code:select.java
List<Customer> customers = sorm.readList(Customer.class, "SELECT * FROM customer WHERE name=? AND age=?","Alice",30);
/yuunkjm/--.icon
Update
Sorm4j supports SQL with SQL parameter container object.
Example
Table schema
We assume the follwing customer table in example.
code:sql
CREATE TABLE customer (id INT PRIMARY KEY, name VARCHAR)
SQL parameter container
code:java
// Table name candidates are "CUSTOMER" and "CUSTOMERS"
public class Customer{
public int id;
public String name;
}
code:java
Customer customer = new Customer(99, "Alice");
// inserts a customer object (Customer class is mapped to the table customer automatically)
sorm.insert(customer);
// convert internally
sorm.executeUpdate("INSERT INTO customer (id, name) VALUES (?,?)", 99, "Alice");
// convert internally
PreparedStatement stmt = new PreparedStatement("INSERT INTO customer (id, name) VALUES (?,?)");
stmt.setInt(1, 99);
stmt.setString(2, "Alice");
code:java
// Insert target is indicate explicitly
sorm.insertOn("another_customer_table", customer);
sorm.deleteOn("another_customer_table", customer);