Android 使用eclipse中的微调器框连接Microsoft SQL Server 2012,
我能够从我的Android应用程序连接到我的SQL Server 2012,并在eclipse的LogCAT中查看结果,我正在尝试的是在Android微调器中获得结果Android 使用eclipse中的微调器框连接Microsoft SQL Server 2012,,android,sql-server-2012,Android,Sql Server 2012,我能够从我的Android应用程序连接到我的SQL Server 2012,并在eclipse的LogCAT中查看结果,我正在尝试的是在Android微调器中获得结果 try{ Log.i("Android"," MySQL Connect Example."); Connection conn = null; String driver = "net.sourceforge.jtds.jdbc.Driver"; Class.forName(driver).n
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();
就像我说的,我可以连接到服务器,并且可以在日志中看到结果,但是想添加到微调器,不知道如何从
中获取,而(reset.next()){
到微调器。我得到了它…只需更改此部分:
while(reset.next()){
Spinner spinner = (Spinner)findViewById(R.id.employee);
Log.w("DataData",reset.getString(2));
致:
1.不要这样做(不要在android平台上直接使用jdbc)在windows平台上,我会为此使用一些WCF REST服务2.搜索适配器教程…(您需要将所有数据放入ArrayList,然后将其与ArrayAdapter一起使用)
if(room!=null){
do {
RoomData.add(new RoomListDB(room.getString(3)));
}
while(room.next());{
}