@Override public void add(User user) { String add = String.format( "insert into Users (name, age) values ('%s', '%d')", user.getName(), user.getAge()); executor.execUpdate(add); }
public User getById(long id) { String select = String.format("select * from users where id = '%d'", id); return executor.execQuery( select, resultSet -> { if (resultSet.absolute(1)) { return new User( resultSet.getLong("id"), resultSet.getString("name"), resultSet.getInt("age")); } else { return null; } }); }
@Override public void update(User user) { String update = "update Users set name = " + "'" + user.getName() + "', age = '" + user.getAge() + "' where id = " + "'" + user.getId() + "'"; executor.execUpdate(update); }