how to update a field value of a data store in google app engine using java

烈酒焚心 提交于 2019-12-03 06:44:34

If you want to update an entity, you have two options:

A. Retrieve this entity from the Datastore by its id. Update property. Put it back into the Datastore.

try {
    loginEntity = datastore.get(KeyFactory.createKey("login", id));
    loginEntity.setProperty("password", "admin@123");
    datastore.put(loginEntity);
} catch (EntityNotFoundException e) {
// This should never happen
}

B. Create a new entity using the same id. Add all properties. Put in a Datastore - it will override the old entity.

Entity loginEntity = new Entity("login", id);
loginEntity.setProperty("password", "admin@123");
datastore.put(loginEntity);

In both examples id is the id of your entity that you want to change.

I hope you do not store passwords as strings.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!