将 SQL 查询结果保存到 Android ArrayList
我试图了解如何将 Android 中的 SQL 查询结果保存到数组列表中。实际上我发现了一些问题,但没有一个可以回答为什么我的代码是错误的。所以这就是我想要做的:
String query = null;
query = "SELECT * FROM users WHERE objectId = "+objectId+" AND serverName "+serverName;
SQLiteDatabase db;
// Insert results from query in database.
ArrayList <String[]> result = new ArrayList<String[]>();
ResultSet rs = db.execSQL(query);
int columnCount = rs.getMetaData().getColumnCount();
while(rs.next())
{
String[] row = new String[columnCount];
for (int i=0; i <columnCount ; i++)
{
row[i] = rs.getString(i + 1);
}
result.add(row);
}
错误是说我无法将 void 转换为 ResultSet。 任何建议如何解决这个问题或者哪个是正确的方法。
提前致谢
I'm trying to understand how to save result from SQL queries in android to an arraylist. Actually I find a few questions but none of them can answer why my code is wrong. So here is what I'm trying to do :
String query = null;
query = "SELECT * FROM users WHERE objectId = "+objectId+" AND serverName "+serverName;
SQLiteDatabase db;
// Insert results from query in database.
ArrayList <String[]> result = new ArrayList<String[]>();
ResultSet rs = db.execSQL(query);
int columnCount = rs.getMetaData().getColumnCount();
while(rs.next())
{
String[] row = new String[columnCount];
for (int i=0; i <columnCount ; i++)
{
row[i] = rs.getString(i + 1);
}
result.add(row);
}
And the error is saying that I cannot convert void to ResultSet.
Any suggestions how to fix that or which is the right way to do this.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一旦数据库打开供读取,请使用 db.query 或 db.rawQuery 获取可用于创建 ArrayList 的游标
Once your database is open for reading use db.query or db.rawQuery to get a cursor that can be used to create your ArrayList