コード例 #1
0
 @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);
 }
コード例 #2
0
 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;
         }
       });
 }
コード例 #3
0
 @Override
 public void update(User user) {
   String update =
       "update Users set name = "
           + "'"
           + user.getName()
           + "', age = '"
           + user.getAge()
           + "' where id = "
           + "'"
           + user.getId()
           + "'";
   executor.execUpdate(update);
 }