我从我的 Android 应用程序连接到 PC 上的 MySQL 数据库。
我正在为此使用 java.sql.jdb。现在我想让我的结果集进入 android.database.cursor??
我该怎么做...? 那是我在 android 应用程序中使用的代码,它获取数据库的结果但无法转换为 Cursor:
Connection connect = null;
ResultSet resultSet = null;
Statement statement = null;
try {
connect = DriverManager.getConnection("jdbc:mysql://"+DbHelper.DB_Path+"/"+DbHelper.DB_Name+"?"
+ "user="+ DbHelper.DB_UserName+ "&password="+ DbHelper.DB_Pass);
statement = connect.createStatement();
// Result set get the result of the SQL query
resultSet = statement
.executeQuery("Select * from btag_store "+
"Where "+
"guid='"+filterArgs+"'");
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Cursor cc;
cc = (Cursor) resultSet; // error in type casr
我知道类型转换会给我错误,但有没有其他方法......??
谢谢
最佳答案
简单地说,你不能。除非你愿意做所有的工作来定义一个对象来实现 Cursor
接口(interface)并使用 ResultSet
来实现 Cursor
的实现细节.不过,这有点愚蠢,因为 ResultSet
对象已经设计为迭代从数据库返回的结果。最干净的方法是按预期使用 ResultSet
对象。
关于android - ResultSet 到 Android Cursor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19265488/