从android中的pre-complie语句获取结果集
我已经创建了下面给出的符合性声明。现在我的问题是如何获得查询的结果集。 这是我的密码:从android中的pre-complie语句获取结果集,android,sqlite,prepared-statement,Android,Sqlite,Prepared Statement,我已经创建了下面给出的符合性声明。现在我的问题是如何获得查询的结果集。 这是我的密码: DataBaseHelper dbHelper=new DataBaseHelper(context); dbHelper.createDataBase(); dbHelper.openDataBase(); SQLiteDatabase db = dbHelper.getWritableDatabase(); SQLiteStatement st=db.compileStatement("select ta
DataBaseHelper dbHelper=new DataBaseHelper(context);
dbHelper.createDataBase();
dbHelper.openDataBase();
SQLiteDatabase db = dbHelper.getWritableDatabase();
SQLiteStatement st=db.compileStatement("select taskid from task where taskdate=?");
st.bindString(1,"2011/09/05");
st.execute();
这工作没有任何错误。但是我想要给定查询的结果集。请帮助..结果集在sqlite中不可用,至少目前不可用。这完全取决于您想要从ResultSet或ResultSetMetaData等中获得什么信息,但是还有其他方法可以获得几乎相同的信息 您可以通过以下内容获得表中列的详细信息,就像选择一样使用,并且将显示有关列的信息:
pragma table_info(myTable) ;
有关更多信息,请参阅
如果需要有关特定选择的信息,可以从结果光标获取信息。看
例如,如果您想要列的数据类型,可以在较新版本的Android中使用getType()方法,或者使用一系列“get”函数来确定至少哪种类型是可读的,代码如下:
Cursor curs = db.rawQuery(sqlStr, null);
int numberOfColumns = curs.getColumnCount();
String []colNames = new String[numberOfColumns];
String []colTypes = new String[numberOfColumns];
for(int iCol=1; iCol<=numberOfColumns; iCol++) {
colNames[iCol-1] = curs.getColumnName(iCol-1);
colTypes[iCol-1] = null; //curs.getType(iCol);
}
while(curs.moveToNext()) {
// this code assumes that the first row has the same data types
// as the rest of the rows
for(int iCol=1; iCol<=numberOfColumns; iCol++) {
String colName = colNames[iCol-1];
String colType = colTypes[iCol-1];
if(colType==null) {
// determine column type
try {
curs.getString(iCol-1);
colType = colTypes[iCol-1] = "text";
} catch (Exception ignore) {
try {
curs.getLong(iCol-1);
colType = colTypes[iCol-1] = "integer";
} catch (Exception ignore1) {
try {
curs.getFloat(iCol-1);
colType = colTypes[iCol-1] = "real";
} catch (Exception ignore2) {
try {
curs.getBlob(iCol-1);
colType = colTypes[iCol-1] = "blob";
} catch (Exception ignore3) {
colType = colTypes[iCol-1] = "other";
}
}
}
}
}
if("text".equals(colType)) {
... curs.getString(iCol-1);
} else
if("real".equals(colType)) {
... curs.getDouble(iCol-1);
} else
if("integer".equals(colType)) {
... curs.getInt(iCol-1);
} else { // unknown type
... colType+"-"+curs.getString(iCol-1);
}
}
}
Cursor curs=db.rawQuery(sqlStr,null);
int numberOfColumns=curs.getColumnCount();
String[]colNames=新字符串[numberOfColumns];
String[]colTypes=新字符串[numberOfColumns];
对于(int iCol=1;iColI尝试了这段代码,getString适用于每一列,因此所有内容都作为字符串加载。