嗨,我在 android 中创建了一个 SQLite 数据库,我最初在其中插入了两条记录,但是在执行数据时没有插入数据,数据库显示为空。任何人都可以帮我插入数据
在下面给出我的数据库类
public class DummyDatabase extends SQLiteOpenHelper{
public static final int NAME_COLUMN=2;
static final String DATABASE_NAME = "NestDatabase.db";
static final int DATABASE_VERSION = 1;
static final String tableName="Employees";
static final String DATABASE_CREATE = "create table "
+ " Employees "+ " " + " "
+ " ( "
+ " ID "
+ " integer primary key autoincrement , "
+ " NAME text ,
EMPLOYEE_CODE text,"
+ " MOBILE_NUMBER integer ); ";
public SQLiteDatabase db;
private final Context context;
public DataBaseHelper1 dbHelper;
public DummyDatabase(Context _context) {
super(_context,DATABASE_NAME, null,DATABASE_VERSION);
// TODO Auto-generated constructor stub
context=_context;
dbHelper=new DataBaseHelper1(_context,DATABASE_NAME,
null,DATABASE_VERSION);
}
public DummyDatabase open() throws SQLException
{
db=dbHelper.getWritableDatabase();
return this;
}
public void close()
{
db.close();
}
public int deleteEntry(String NAME)
{
String where="NAME=?";
int numberOFEntriesDeleted= db.delete("Employees", where, new String[]
{NAME}) ;
Toast.makeText(context, "Number fo Entry Deleted Successfully :
"+numberOFEntriesDeleted, Toast.LENGTH_LONG).show();
return numberOFEntriesDeleted;
}
public String getEntry(String Emp_code)
{
Cursor cursor=db.query("Employees", null, " EMPLOYEE_CODE=?", new
String[]{Emp_code}, null, null, null);
if(cursor.getCount()<1) // UserName Not Exist
return "NOT EXIST";
cursor.moveToFirst();
String user= cursor.getString(cursor.getColumnIndex("NAME"));
return user;
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL(DATABASE_CREATE);
db.execSQL("insert into Employees( NAME , EMPLOYEE_CODE , MOBILE_NUMBER)
"+" values ('Alexander','A111','1234567890');");
db.execSQL("insert into Employees( NAME , EMPLOYEE_CODE , MOBILE_NUMBER)
"+" values ('Bernie','B111','1234567890');");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
Log.w("TaskDBAdapter","Upgrading from
version"+oldVersion+"to"+newVersion+",which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS"+"TEMPLATE");
onCreate(db);
}
}