0

I use a JTDS jar to connect my application android with DB (SQL SERVER) the problem that the (databaseName,user,password) are in Class in my project

ConnURL = "jdbc:jtds:sqlserver://" + **** + ";"
                + "databaseName=" +***** + ";user=" + **** + ";password=****"

is there a solution to hide my (databaseName,user,password)

if someone decompile my app it will have access to DB how can I avoid this big problem

Mc Sousi
  • 21
  • 3
  • why dont use api for it so you can modify from server, if you distribute your apps how you will control your apps behaviour? – Iqbal Rizky Feb 20 '17 at 22:45
  • Have a look at this [SO Q/A](http://stackoverflow.com/questions/19217835/can-an-android-app-connect-directly-to-an-online-mysql-database) – boxed__l Feb 20 '17 at 22:47

1 Answers1

1

If the app will act as a client-side application:

A better approach would be not to let the application communicate directly with the DB.

Instead, have a server running as a web-service to act as an in-between layer between the application and the DB. This way, only the server has access to the data in the DB, and the applications can only interact with the APIs defined by your server, which can guard against things such as malicious SQL statements.

If the app is a server-side app:

It is a good idea to avoid hardcoding DB information into your application (because changing the app would require an app recompile).

To avoid encoding DB information directly in your application code, you could store DB information in an external .properties file, such as:

db.server=myserver.com
db.name=myDB
db.user=user1
db.pass=pass1

Then you could distribute your application and properties file separately, or encrypt the properties file.

Then load the properties file at runtime:

Properties dbProps = new Properties();
InputStream is = new FileInputStream("database.properties");
prop.load(is);

String connURL = "jdbc:jtds:sqlserver://" + 
          dbProps.getProperty("db.server") + 
          ";databaseName=" + dbProps.getProperty("db.name") + 
          ";user=" + dbProps.getProperty("db.user") + 
          ";password=" dbProps.getProperty("db.pass");
Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
  • Could you pl explain what you mean by server-side android app? Aren't all Android applications client-side? – boxed__l Feb 21 '17 at 18:48
  • You are correct -- all android apps are client-side. From your original question it was not clear whether or not this code would be running in an android app, or in a server-side app that an android app was communicating with. – Andy Guibert Feb 21 '17 at 19:41
  • hey I didn't write the question!! – boxed__l Feb 21 '17 at 19:56