Android应用程序将在数据库服务器中显示来自外部数据库(Oracle)的数据。这只能通过网络服务(RESTful)实现,所以我决定使用 Java/Java EE 本身开发 Web 服务。 我不想使用 PHP 或其他一些技术。请建议我继续执行此操作。
最佳答案
取决于网络服务。它只是 RESTful XML 吗? JAX-WS? JSON?等等。无论哪种方式,都应该像使用 HTTP 套接字调用并解析响应一样简单。
要创建网络服务,请点击以下链接
使用 HTTPClient
public static String hitService(String host, int port, String path, String postBody) throws IOException {
HttpHost target = new HttpHost(host, port);
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(path);
HttpEntity results = null;
try {
HttpResponse response=client.execute(target, get);
results = response.getEntity();
return EntityUtils.toString(results);
} catch (Exception e) {
throw new RuntimeException("Web Service Failure");
} finally {
if (results!=null)
try {
results.consumeContent();
} catch (IOException e) {
// empty, Checked exception but don't care
}
}
}
关于java - 如何从 Android 应用程序访问 Oracle 数据库。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7964350/