我可以从我的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).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 :(得分: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());{
}