【发布时间】:2011-04-14 16:20:19
【问题描述】:
我想预先填写并定期将数据放入 Google Appengine 数据库。
我想用 java 和 python 编写一个程序,连接到我的 GAE 服务并将数据上传到我的数据库。
我该怎么做?
谢谢
【问题讨论】:
标签: java python google-app-engine
我想预先填写并定期将数据放入 Google Appengine 数据库。
我想用 java 和 python 编写一个程序,连接到我的 GAE 服务并将数据上传到我的数据库。
我该怎么做?
谢谢
【问题讨论】:
标签: java python google-app-engine
请使用 RemoteAPI 以编程方式执行此操作。
在python中,您可以先配置appengine_console.py,如here所述
一旦你有了它,你就可以在 python shell 中启动并编写以下命令:
$ python appengine_console.py yourapp
>>> import yourdbmodelclassnamehere
>>> m = yourmodelclassnamehere(x='',y='')
>>> m.put()
这里是java版本的代码,不言自明(直接借用remote api page on gae docs):
package remoteapiexample;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.tools.remoteapi.RemoteApiInstaller;
import com.google.appengine.tools.remoteapi.RemoteApiOptions;
import java.io.IOException;
public class RemoteApiExample {
public static void main(String[] args) throws IOException {
String username = System.console().readLine("username: ");
String password =
new String(System.console().readPassword("password: "));
RemoteApiOptions options = new RemoteApiOptions()
.server("<your app>.appspot.com", 443)
.credentials(username, password);
RemoteApiInstaller installer = new RemoteApiInstaller();
installer.install(options);
try {
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
System.out.println("Key of new entity is " +
ds.put(new Entity("Hello Remote API!")));
} finally {
installer.uninstall();
}
}
}
【讨论】: