我想將我的android應用程序連接到我的MSSQL數據庫。 不幸的是,有一個問題:/ClassNotFoundException - 連接到MSSQL數據庫
10-25 19:17:00.536: W/System.err(18961): java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver 10-25 19:17:00.546: W/System.err(18961): at java.lang.Class.classForName(Native Method) 10-25 19:17:00.556: W/System.err(18961): at java.lang.Class.forName(Class.java:217) 10-25 19:17:00.556: W/System.err(18961): at java.lang.Class.forName(Class.java:172) 10-25 19:17:00.556: W/System.err(18961): at com.example.mssqlcon.MainActivity.onCreate(MainActivity.java:21) 10-25 19:17:00.556: W/System.err(18961): at android.app.Activity.performCreate(Activity.java:4465) 10-25 19:17:00.556: W/System.err(18961): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 10-25 19:17:00.556: W/System.err(18961): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033) 10-25 19:17:00.556: W/System.err(18961): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104) 10-25 19:17:00.556: W/System.err(18961): at android.app.ActivityThread.access$600(ActivityThread.java:132) 10-25 19:17:00.556: W/System.err(18961): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157) 10-25 19:17:00.556: W/System.err(18961): at android.os.Handler.dispatchMessage(Handler.java:99) 10-25 19:17:00.556: W/System.err(18961): at android.os.Looper.loop(Looper.java:137) 10-25 19:17:00.566: W/System.err(18961): at android.app.ActivityThread.main(ActivityThread.java:4575) 10-25 19:17:00.566: W/System.err(18961): at java.lang.reflect.Method.invokeNative(Native Method) 10-25 19:17:00.566: W/System.err(18961): at java.lang.reflect.Method.invoke(Method.java:511) 10-25 19:17:00.566: W/System.err(18961): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 10-25 19:17:00.566: W/System.err(18961): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556) 10-25 19:17:00.566: W/System.err(18961): at dalvik.system.NativeStart.main(Native Method) 10-25 19:17:00.566: W/System.err(18961): Caused by: java.lang.NoClassDefFoundError: net/sourceforge/jtds/jdbc/Driver 10-25 19:17:00.566: W/System.err(18961): ... 18 more 10-25 19:17:00.566: W/System.err(18961): Caused by: java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver 10-25 19:17:00.576: W/System.err(18961): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61) 10-25 19:17:00.576: W/System.err(18961): at java.lang.ClassLoader.loadClass(ClassLoader.java:501) 10-25 19:17:00.576: W/System.err(18961): at java.lang.ClassLoader.loadClass(ClassLoader.java:461) 10-25 19:17:00.576: W/System.err(18961): ... 18 more
我的代碼:
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection(
"jdbc:jtds:sqlserver://ip_of_my_database", "*****", "*******");
Statement statement = connection.createStatement();
//ResultSet result = statement
// .executeQuery("SELECT * FROM nazwatabeli");
ResultSet result = statement.executeQuery("SELECT * FROM name");
if(result.first()){
do{
Log.v("MainActivity", "Name: "+result.getString(result.getRow()));
} while(result.next());
}
} catch (Exception e){
e.printStackTrace();
}
}
}
我做什麼了?
r20?這是Api級別?我的Api級別是8. – user1019901
實際上我無法訪問我的MSSQL數據庫? – user1019901
這不是關於API。這是SDK版本。您可以通過打開Android SDK來檢查它,而關於該選項的選項會告訴您在工具中使用的SDK版本是什麼。 – Chamath