Ontarianmm
Ontarianmm

Reputation: 11

Error: no suitable drivers for jdbc in android studio

I am aware that there is a number of people having issues on here about this. I have read through a number of them but haven't any of their solutions to help me.

I have included the library in my app build.gradle:

 apply plugin: 'com.android.application'

 android {
...
 dependencies {
     compile fileTree(include: ['*.jar'], dir: 'libs')
     testCompile 'junit:junit:4.12'
     compile 'com.android.support:appcompat-v7:23.1.1'
     compile 'com.android.support:support-v4:23.1.1'
     compile 'com.google.android.gms:play-services:8.4.0'
     compile 'com.android.support:multidex:1.0.1'
     compile 'com.microsoft.azure.android:azure-storage-android:0.7.0@aar'
     compile 'com.android.support:design:23.1.1'
     compile files('libs/mysql-connector-java-5.0.8/mysql-connector-java-5.0.8-bin.jar')
 }

I have a classpath in the project build.gradle:

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.1'
        classpath 'com.google.gms:google-services:1.3.0-beta1'
        classpath 'mysql:mysql-connector-java:5.0.8'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

}

I have the lib in the library folder:

[My lib folder]

and I have implimented getting the drivers in my program:

String hostName = "whereyaatserver.database.windows.net";
String dbName = "whereyaatdatabase";
String user = "Capstone_Admin";
String password = "Swde4321!";
String url = "jdbc:sqlserver://whereyaatserver.database.windows.net:1433;database=whereyaatdatabase;user=Capstone_Admin@whereyaatserver;password=Swde4321!;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;";
        Connection connection = null;

public Mapping() throws SQLException {
}


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mapping);
    try {
        Class.forName("com.mysql.jdbc.Driver");
        connection = DriverManager.getConnection(url);
    } catch (SQLException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

and I have added a CLASSPATH variable to the environment variable point into my lib folder:

[my CLASSPATH variable]

I am not entirely sure where I am going wrong. I clearly am in some why but I am not sure if I am making a small mistake or going about this entirely the wrong way. Any guidance would be appreciated.

Upvotes: 0

Views: 2749

Answers (1)

Ontarianmm
Ontarianmm

Reputation: 11

I have solved it thanks to the aid of a comment by CommonsWare. The issue was that I had imported the mysql library rather than the sql library.

Here are the new dependencies:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
    compile 'com.google.android.gms:play-services:8.4.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.microsoft.azure.android:azure-storage-android:0.7.0@aar'
    compile 'com.android.support:design:23.1.1' //  compile files('libs/mysql-connector-java-5.0.8/mysql-connector-java-5.0.8-bin.jar')
    compile files('libs/sqljdbc_6.0/enu/jre7/sqljdbc41.jar')
}

And the new lib folder:

[New Lib folder]

Just putting this here in case someone else is as silly as I

Upvotes: 1

Related Questions