2014-08-29 59 views
-1

我能夠從我的Android應用程序連接到我的SQL Server 2012,並在eclipse中查看LogCAT中的結果,我試圖做的是獲得結果一個android微調。用eclipse中的微調框連接Microsoft SQL Server 2012,

try{ 
    Log.i("Android"," MySQL Connect Example."); 
    Connection conn = null; 

    String driver = "net.sourceforge.jtds.jdbc.Driver"; 
    Class.forName(driver).newInstance(); 
    //test = com.microsoft.sqlserver.jdbc.SQLServerDriver.class; 
    String connString = "jdbc:jtds:sqlserver://xxxx:1433;user=admin;password=admin;"; 
    String username = "admin"; 
    String password = "admin"; 
    conn = DriverManager.getConnection(connString,username,password); 
    Log.w("Connection","open"); 
    Statement stmt = conn.createStatement(); 
    ResultSet reset = stmt.executeQuery("select * from test"); 

    //Print the data to the console 
    while(reset.next()){ 
    // Spinner spinner = (Spinner)findViewById(R.id.employee); 
    Log.w("DataData",reset.getString(2)); 
    } 
    conn.close(); 
} catch (Exception e) 
{ 
    e.printStackTrace(); 

就像我說的,我可以連接到服務器,並能在日誌中看到的結果,但要添加到微調,不知道如何從while(reset.next()){得到一個微調。

+0

1.不這樣做(不使用JDBC直接在android平臺)上Windows平臺,我會使用一些WCF REST服務這2。搜索適配器教程...(你需要ArrayList 在那裏你把所有的數據在這個循環,那麼你應該使用它與ArrayAdapter ) – Selvin 2014-08-29 11:40:23

回答

0

我...只是不得不改變這一部分:

while(reset.next()){ 
Spinner spinner = (Spinner)findViewById(R.id.employee); 
Log.w("DataData",reset.getString(2)); 

到:

if(room!=null){ 
    do { 

      RoomData.add(new RoomListDB(room.getString(3))); 
     } 
      while(room.next());{ 
     }