I want to connect my android application with a SQL database which is stored in an another computer. I want to use that computer as a server. I think there is a method to connect with that server computer using it's IP address. I use android studio when developing the android application. Can anyone help me to fix this problem?
Asked
Active
Viewed 1,526 times
1 Answers
0
I would not recommend you to connect directly to the database from the application, if you plan to publish the app. You open a port to the database server to everyone and store the password to the database in the user device. Anyone who wants to retrieve data from your SQL Server just needs to open the application in a hex editor or decompile it in order to retrieve the password.
Always use an API through a webserver that gets you desired information. You could use the Firebase Realtime Database to sync specific data, if you do not trust Google then build your own API. https://firebase.google.com/docs/database/

Simon
- 605
- 1
- 6
- 18
-
Thank you for your guide. It helped me a lot. – Methmal Godage Apr 18 '17 at 14:58
-
Please be kind enough to give me an example code which is using direct IP address method. Because I couldn't find a proper code in internet. – Methmal Godage Apr 18 '17 at 15:39
-
I would try just entering IP-Address instead of domainname. I do not know how it will work with TLS Encryption, because certificate will be invalid, you will have to handle that error. You could try using only http, but your data is not encrypted then. FirebaseOptions options = new FirebaseOptions.Builder() .setCredential(FirebaseCredentials.fromCertificate(serviceAccount)) .setDatabaseUrl("https://192.168.0.5") .setDatabaseAuthVariableOverride(null) .build(); (from: https://firebase.google.com/docs/database/admin/start) – Simon Apr 18 '17 at 18:47
-
Thank you I'll try this. – Methmal Godage Apr 19 '17 at 03:13