I am working on an android app and have to use remote database for data storage.I have two options, first create a REST API using php.Second option is connect directly to mysql db with JDBC using mysql-connector-java-5.1.18-bin.jar. I am not familiar with second one but i want to confirm which method will be feasible and why?.
我正在开发一个Android应用程序,并且必须使用远程数据库进行数据存储。我有两个选项,首先使用php创建一个REST API。第二个选项是使用mysql-connector-java-5.1.18直接连接到mysql db和JDBC -bin.jar置于。我不熟悉第二个,但我想确认哪种方法可行,为什么?
2 个解决方案
#1
2
You can't use second (jdbc) method with android application (SO Reference thread). You have to use REST API.
你不能使用第二个(jdbc)方法与Android应用程序(SO参考线程)。您必须使用REST API。
#2
1
You cannot use normal JDBC connection method to a remote to a db server from your android phone as you do normally in a Java application. This is because Java application normally runs a machine which is either on a network or can connect to a network or has the mysql database on it which is not the case with your android phone.
您不能像在Java应用程序中那样在Android手机上使用普通的JDBC连接方法到远程数据库服务器。这是因为Java应用程序通常运行一台机器,该机器在网络上或者可以连接到网络或者在其上有mysql数据库,这与你的Android手机不同。
The alternatives you have are
你有的替代品是
-
Create webservice (REST or SOAP) and invoke it from your device // As you mentioned
创建Web服务(REST或SOAP)并从您的设备调用它//如您所述
-
Create a Servlet which can service a POST or GET request, and invoke it from your device.
创建一个可以为POST或GET请求提供服务的Servlet,并从您的设备调用它。
Cheers, RJ
干杯,RJ
#1
2
You can't use second (jdbc) method with android application (SO Reference thread). You have to use REST API.
你不能使用第二个(jdbc)方法与Android应用程序(SO参考线程)。您必须使用REST API。
#2
1
You cannot use normal JDBC connection method to a remote to a db server from your android phone as you do normally in a Java application. This is because Java application normally runs a machine which is either on a network or can connect to a network or has the mysql database on it which is not the case with your android phone.
您不能像在Java应用程序中那样在Android手机上使用普通的JDBC连接方法到远程数据库服务器。这是因为Java应用程序通常运行一台机器,该机器在网络上或者可以连接到网络或者在其上有mysql数据库,这与你的Android手机不同。
The alternatives you have are
你有的替代品是
-
Create webservice (REST or SOAP) and invoke it from your device // As you mentioned
创建Web服务(REST或SOAP)并从您的设备调用它//如您所述
-
Create a Servlet which can service a POST or GET request, and invoke it from your device.
创建一个可以为POST或GET请求提供服务的Servlet,并从您的设备调用它。
Cheers, RJ
干杯,RJ