从SQLite数据库读取Android
我不知道为什么这会使我的应用程序崩溃。我已经导入了一个在sqlite上创建的数据库,现在我只想从中读取信息 这是我的密码从SQLite数据库读取Android,android,database,sqlite,Android,Database,Sqlite,我不知道为什么这会使我的应用程序崩溃。我已经导入了一个在sqlite上创建的数据库,现在我只想从中读取信息 这是我的密码 public class goodwillDatabase { private static final String DATABASE_NAME="goodwill"; private SQLiteDatabase ourDatabase; //set up variables static fin
public class goodwillDatabase {
private static final String DATABASE_NAME="goodwill";
private SQLiteDatabase ourDatabase;
//set up variables
static final String candidate_id = "_id";
static final String candidate_name = "name";
static final String candidate_street_address = "email";
//set up the table...store different tables in database
private static final String DATABASE_TABLE = "candidate";
private static final int DATABASE_VERSION = 1;
//create instance of this class
//creates, opens and closes database
private DbHelper ourHelper;
private final Context ourContext;
//create database on a different thread
private static class DbHelper extends SQLiteOpenHelper{
public DbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
//first time we ever create database, this is called
@Override
public void onCreate(SQLiteDatabase db) {
}
//if already created, just update
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion,
int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS" + DATABASE_TABLE);
onCreate(db);
}
}
public goodwillDatabase(Context c){
//make context of this class equal to whatever is being passed in
ourContext = c;
}
//opens database
//sql excpetion for the try catch
public goodwillDatabase open() throws SQLException{
//create a new helper, pass in context from the method above
ourHelper = new DbHelper(ourContext);
ourDatabase = ourHelper.getWritableDatabase();
return this;
}
//closes the class...sqlite helper, dbhelper
public void close(){
ourHelper.close();
}
public String getData() {
// TODO Auto-generated method stub
//create a new helper, pass in context from the method above
String [] columns = new String []{ candidate_name, candidate_street_address};
Cursor d = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
String result = " ";
//String[] result = columns;
/*
int iRow = c.getColumnIndex(canadiate_id);
int iName = c.getColumnIndex(canadiate_name);
int iStreet = c.getColumnIndex(canadiate_street_address);*/
/*
//start at the beginning, keep moving if you haven't made it to the last
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext())
{
result = result + c.getString(iRow) + " " + c.getString(iName) +
" " + c.getString(iStreet) + "\n";
}
*/
return result;
}
}
*游标d=ourDatabase.query(数据库_表,列,null,null,null,null);*线路就是它崩溃的地方。是不是光标不知道指向哪里?我不是一个超级熟悉的数据库或编程,所以任何帮助,你可以给我将不胜感激 试试看
Cursor d = ourDatabase.rawQuery("select name,email from candidate",null);
query和rawQuery的作用是相同的,但有时它们中的任何一个都可以工作,而另一个则不行:(Try
Cursor d = ourDatabase.rawQuery("select name,email from candidate",null);
query和rawQuery的作用相同,但有时它们中的任何一个都可以工作,而另一个则不能:(请发布错误本身的日志。错误是--对不起!应用程序商誉(process goodness.database)已意外停止,请重试。--以下是一个示例。如果您使用Eclipse,此窗口的默认位置在屏幕的右下角。没有此信息,我们只能盲目猜测。请发布错误本身的日志。错误是--抱歉!应用程序商誉(process goodwill.database)已意外停止,请重试。--以下是一个示例。如果您使用Eclipse,此窗口的默认位置位于屏幕的右下角。如果没有此信息,我们只能盲目猜测。