IBM Worklight SQL adapter for real device

拥有回忆 提交于 2019-12-13 01:23:45

问题


If i use local database, say MySQL, it works perfect on simulator and emulator but for real device, localhost won't do, So i tried online database hosting.

When using online hosting from www.freemysqlhosting.net, i had setup the database in my database development perspective in Eclipse using the provided id and password, so it worked well on my simulator, emulator and real device that was connected to the same network as that system on which that database was setup, but for any anonymous device,it failed!

Then i tried with sqllite, again it worked with simulator and emulator but for real device,it showed UNRESPONSIVE_HOST error.

My question is: if i want to develop an app using IBM Worklight that uses some database and want to distribute it, how can i do it?


回答1:


Your problem is not with the SQL server it is with the connection between the device and the Worklight server. You need to be able to connect from the device to the Worklight server. Open a browser on the device and point it to the Worklight console and see that you can access it.




回答2:


It would have been far far more helpful if you'd just provide the error log from LogCat...

When using Android, it is a good practice to not use localhost, instead to use the actual IP address. See this question: IBM Worklight - Unable to connect to database when using IP address instead of localhost

MySQL is a server like any other server; if you want to use it outside of your private local network, then you simply need to open it to incoming connections from the public Internet. This is not something a developer needs to fuss around with, that's what IT departments are for. So google and see how to open your network.




回答3:


This sounds as though you are trying to access a database directly from your device. Is that the case?

I would strongly recommend using Worklight Adapters here. So the pattern goes:

 App on Device ---> Adapter ---> Database

In that pattern the responsibility for getting from Device to the Adapter lies with Worklight and hence should be completely unaffected by whether it's a real device or an emulated one, and should also be independent of what particular database you are using or where it it.

The hop from Adapter to Database is something you can set up and test without even having an deployed anywhere. Just use the test environment in Eclipse to call adapter methods.

Why not go from device directly to database? In general that's a really bad security pattern, you're effectively putting data you care about in a very hackable place. Also it will not scale well to large numbers of users: connecting directly from the device means that effectively every user has their own connection, going via the adapter users share a controllable number of connections.



来源:https://stackoverflow.com/questions/23558001/ibm-worklight-sql-adapter-for-real-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!