Android 驱动程序 JDBC PostgreSQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10435609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Driver JDBC PostgreSQL with Android
提问by toshiro92
I'm trying to connect my android application to a server (PostgreSQL) with JDBC Driver, but i have this error :
我正在尝试使用 JDBC 驱动程序将我的 android 应用程序连接到服务器 (PostgreSQL),但出现此错误:
java.lang.ClassNotFoundException: org.postgresql.Driver
...
Caused by: java.lang.NoClassDefFoundError: org/postgresql/Driver
... 12 more
Caused by: java.lang.ClassNotFoundException: org.postgresql.Driver
...
java.sql.SQLException: No suitable driver
I tried many things, like add the address of the driver in the Path, but nothing work. I followed this tutorial : http://appliedcoffeetechnology.tumblr.com/post/10657124340and added the driver JDBC4 (i also tried the JDBC3), in the Build Path.
我尝试了很多东西,比如在路径中添加驱动程序的地址,但没有任何效果。我遵循了本教程:http: //appliedcoffeetechnology.tumblr.com/post/10657124340 并在构建路径中添加了驱动程序 JDBC4(我也尝试了 JDBC3)。
Everybody can help me ?
大家可以帮帮我吗?
回答by Craig Ringer
While not the strict answer to your question, I do have a suggestion.
虽然不是您问题的严格答案,但我确实有一个建议。
Don't try to use JDBC on the Android device directly. You'll save a lot of hassle that way. I wrote about that in more detail on the "JDBC vs Web Service for Android" question.
不要尝试直接在 Android 设备上使用 JDBC。这样你会省去很多麻烦。我在“JDBC vs Web Service for Android”问题上更详细地写了相关内容。
Write your database logic on a web-accessible application server and talk to that application server via HTTP+JSON, SOAP, XML-RPC, or similar. This will be a lot more bandwidth efficient and you can make your app a lot more tolerant of issues with connectivity that way. It also saves you from having to expose your database server directly to the Internet - not much of a worry with PostgreSQL so long as you use SSL, but still better not to have to do at all.
在可通过 Web 访问的应用程序服务器上编写数据库逻辑,并通过 HTTP+JSON、SOAP、XML-RPC 或类似方式与该应用程序服务器通信。这将大大提高带宽效率,并且您可以使您的应用程序对连接问题的容忍度更高。它还使您不必将数据库服务器直接暴露给 Internet - 只要您使用 SSL,PostgreSQL 就不必担心,但最好根本不必这样做。
Using JAX-RS on JBoss AS 7, Tomcat 7, or similar you should be able to put together a web RESTful XML/JSON services API for your app pretty easily. People also seem to put REST/JSON APIs together pretty quickly with PHP.
在 JBoss AS 7、Tomcat 7 或类似版本上使用 JAX-RS,您应该能够非常轻松地为您的应用程序组合一个 Web RESTful XML/JSON 服务 API。人们似乎也很快将 REST/JSON API 与 PHP 结合在一起。
You can write a JSON/REST web API in pretty much any language you like with varying degrees of ease. Just search for REST server yourlanguagename
.
您可以使用几乎任何您喜欢的语言轻松编写 JSON/REST Web API。只需搜索REST server yourlanguagename
.
"Kaw" has pointed out in a deleted answer that there are also virtual JDBC drivers that tunnel requests over HTTP. These may be suitable for some applications.
“Kaw”在一个已删除的回答中指出,还有虚拟 JDBC 驱动程序可以通过 HTTP 隧道请求。这些可能适用于某些应用。