MILK - Java database framework Wiki
Lightweight Java database framework featuring a simple ORM
Status: Alpha
Brought to you by:
lvillap
Updates are queries that change the contents of the database. They are created just like the Selects. The execution of updates, always returns an integer indicating the number of rows that have changed.
import net.sourceforge.milk.sql.Update;
...
// Let's insert a new user
final Update queryInsertUser = new Update(
"Insert user",
"insert into user (name, surname, age, active) values (?,?,?,?)",
new Object[] { "MyName", "MySurname", 38, true });
final Integer numberOfRowsInserted = new IssuesDb().sql().run(
queryInsertUser);
// Now we'll change the data of an user
final Update queryChangeUser = new Update("Change user",
"update user set name=? where name=?", new Object[] {
"AnotherName", "MyName" });
final Integer numberOfRowsChanged = new IssuesDb().sql().run(
queryChangeUser);
// Finally, we'll delete it
final Update queryDeleteUser = new Update("Delete user",
"delete from user where name = ?", new Object[] { "Luis" });
final Integer numberOfRowsDeleted = new IssuesDb().sql().run(
queryDeleteUser);
And that's all that it's to it. Now, for the final step: The use of transactions
Wiki: Examples
Wiki: examples_toc
Wiki: objects_from_queries
Wiki: transactions_and_queries