简体   繁体   English

一种从mysql到Android应用程序获取信息的方法

[英]A way to get information from mysql to Android app

I have an Android app which handles strings with web adresses and connects to them with a webview. 我有一个Android应用程序,该程序可以处理带有Web地址的字符串,并通过WebView连接到它们。

Then I have a mysql db with the strings and some more information. 然后我有一个带有字符串和更多信息的mysql db。

I've read that I should connect my app through a webservice. 我读过我应该通过网络服务连接我的应用程序。 But if I want to store the info on the app, and only connect to the app once in the beginning when I start the app. 但是,如果我要将信息存储在应用程序上,并且在启动应用程序时一开始只连接一次该应用程序。 What is the best way to go at it? 最好的方法是什么?

Can I store all the information from the tables into a local sqlite database? 我可以将表中的所有信息存储到本地sqlite数据库中吗? Are there any tutorials for the whole scenario. 是否有关于整个场景的教程。 Mysql->php webservice->android app sqlite. MySQL的-> PHP的Web服务-> Android应用程序的SQLite。

Best regards Joe 最好的问候乔

Write a servlet (has to run on server on course) in an external dynamic web project that will handle your POST request, connect to the DB and return data. 在一个外部动态Web项目中编写一个servlet(当然要在服务器上运行),它将处理您的POST请求,连接到DB并返回数据。 then add this data to the sqlite database, a perfect tutorial can be found here . 然后将此数据添加到sqlite数据库,可以在此处找到理想的教程。

if you need more info on servlets, sending and getting parameters from a request, let me know 如果您需要有关servlet,从请求发送和获取参数的更多信息,请告诉我

If you have just to "initialize" your db just, creating a whole webservice would be quite overkilling. 如果您只需要“初始化”您的数据库,那么创建一个完整的Web服务就太过分了。 A webservice would be very useful if you want to have your remote db synchronized with all the app (if you have "dynamic" data). 如果要使远程数据库与所有应用程序同步(如果您具有“动态”数据),则Web服务将非常有用。

Maybe you can try to create a sql script, save it in the app and then run it to populate your db. 也许您可以尝试创建一个sql脚本,将其保存在应用程序中,然后运行它以填充数据库。

Here some information on how to use a script from raw folder: android, how to exec a sql file in sqlitedatabase 这里有一些有关如何使用原始文件夹中的脚本的信息: android,如何在sqlitedatabase中执行sql文件

Hope this helps. 希望这可以帮助。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM