0

My connection java file contains :

try {
    Log.i("Login", "Establishing Connection...");
    // SET CONNECTIONSTRING
    Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
    Log.i("JDBC","found");
    Connection DbConn = DriverManager.getConnection("<connection_string>");

    Log.i("Login","Connected");
    Statement stmt = DbConn.createStatement();
    ResultSet insert = stmt.executeQuery("insert into UserLogin(username, password) values (admin, admin);");
    ResultSet reset = stmt.executeQuery(" select * from UserLogin ");

    Toast.makeText(this, reset.getString(1), Toast.LENGTH_SHORT).show();

    DbConn.close();

    // go to newsfeed
} catch (Exception e) {
    Log.e("Error connection","" + e.getMessage());
}

When my connection string contains:
jdbc:jtds:sqlserver://, I gets error in connection :null,and when it's
jdbc:sqlserver://,         I gets error in connection:no suitable driver found.

I'm trying to connect Android with Azure SQL DB.

I've seen Question1, Question2, Question3, Question4.   No Answer.

Community
  • 1
  • 1
Nirav Madariya
  • 1,470
  • 2
  • 24
  • 37
  • 1
    It's recommended to add another part between the Android client and the database server. Something like PHP, ASP.NET, Python, etc. Consider a scenario in which attacker reverse engineer your Android client, then he has a direct access to your database. – frogatto Jul 30 '16 at 18:12

1 Answers1

1

@NiravMadariya, The JDBC connection string with jTDS shoule be jdbc:jtds:sqlserver://<server>:<port>/<database>, please see the jTDS FAQ which includes URL format and the reason for No suitable driver exception.

Note, if you are using the JTDS JDBC driver for Auzre SQL DB, then you will need to add ssl=require to the URL of the connection string as like this jdbc:jtds:sqlserver://<server>:<port>/<database>?ssl=require.

Meanwhile, using Microsoft JDBC Driver for SQL Server is a recommend way for Azure SQL DB, please see https://azure.microsoft.com/en-us/documentation/articles/sql-database-develop-java-simple/.

Peter Pan
  • 23,476
  • 4
  • 25
  • 43