2017-04-24 107 views
0

我知道有一些人在這裏有關於此問題。我已閱讀了其中的一些,但沒有任何解決方案來幫助我。錯誤:沒有合適的驅動程序jdbc在android studio

我已經包含在我的應用程序的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:[email protected]' 
    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') 
} 

我在該項目中的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 
    } 

} 

我在庫文件夾下的lib:

[My lib folder]

,我已經implimented讓司機在我的計劃:

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;[email protected];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(); 
    } 

,我添加了一個變量CLASSPATH環境變量點到我的lib文件夾:

[my CLASSPATH variable]

我不能完全肯定我要去的地方錯了。我明顯在某種原因,但我不確定我是否犯了一個小錯誤,或者以完全錯誤的方式進行。任何指導將不勝感激。

+0

好,最好的答案是「不要在Android應用程序中使用JDBC」。你的'CLASSPATH'沒有意義,因爲那是Windows,而你正在編寫一個在Android上運行的應用程序。而你的'url'似乎是用於SQL Server的,而你的驅動程序似乎是用於MySQL的。 – CommonsWare

+0

如果不使用sql,使用Azure的android數據庫的最佳方式是什麼? – Ontarianmm

+0

我不能說Azure。除此之外,通常我們在與數據庫交談的服務器上使用某種形式的Web服務,移動應用程序與Web服務交談。 – CommonsWare

回答

0

由於CommonsWare的評論,我已經解決了它。問題是我導入了mysql庫而不是sql庫。

這裏是新的依賴:

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:[email protected]' 
    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') 
} 

而新的lib文件夾:

[New Lib folder]

只是把這個在這裏情況下別人是愚蠢的,因爲我

相關問題