2013-03-07 129 views
1

我厭倦了搜索沒有結果我不知道問題來自哪裏,我試圖連接我的android應用程序與本地SQl服務器2008年,現在我得到無法從sql server獲取信息。請幫助,這是我的代碼:使用jtds連接android應用程序到sql server

String url = "jdbc:jtds:sqlserver://10.0.2.2:1433/lear_db;instance=SQLEXPRESS;"; 
TextView coucou = new TextView(this); 

    try { 
     Class.forName("net.sourceforge.jtds.jdbc.Driver"); 
     java.sql.Connection connexion =    
     DriverManager.getConnection(url,"kamal","kamal1234"); 

     coucou.setText("Connection successful"); 

    } catch (SQLException e) { 
     // TODO Auto-generated catch block 
     coucou.setText("error1" + e.getMessage()); 
     e.printStackTrace(); 
    } catch (ClassNotFoundException e) { 
     // TODO Auto-generated catch block 
     coucou.setText("error2" + e.getMessage()); 
     e.printStackTrace(); 

    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     coucou.setText("error0" + e.getMessage()); 
     e.printStackTrace(); 
    } 
    setContentView(coucou); 
+0

查看我的[回覆](http://stackoverflow.com/a/15273775/2024761)以查看'JAR'是否存在。如果它仍然存在,那麼跟蹤粘貼錯誤堆棧。 – SudoRahul 2013-03-07 16:51:58

回答

0

通常情況下,我使用的jdbc:SQLSERVER這個FASION

String url = "jdbc:sqlserver://10.0.2.2:1433/lear_db;instance=SQLEXPRESS;"; 

或者相反,如果使用JTDS,嘗試:

String url = "jdbc:jtds://10.0.2.2:1433/lear_db;instance=SQLEXPRESS;"; 
+0

對於第一個1:我得到沒有合適的驅動程序,第二我得到的連接url的語法是無效的 – Overflow 2013-03-07 17:20:32

+0

jdbc:sqlserver是一個微軟的驅動程序,我希望它適用於Android,嘗試一下http:// www.microsoft.com/en-us/download/details.aspx?id=11774 – extofer 2013-03-09 04:16:26

+0

感謝extofer爲您的迴應,但JTDS爲我工作 – Overflow 2013-03-13 10:55:52

0

這是聯接爲我工作的字符串:

「jdbc:jtds:sqlserver://」+ adresseip +「:1433/lear_db; user = youruser; password = yourpass」

比我得到的其他錯誤至極爲:android.os.NetworkOnMainThreadException

的解決方案是使用的AsyncTask這是一個教程:http://droidapp.co.uk/2011/05/12/android-dev-pre-loading-with-asynctask/

現在我有一個新的錯誤(這錯誤永遠不會結束):

Unknow server host name 'unable to resolve host 

比它的工作,在主機的ip adresse的WiFi。

相關問題