我尝试使用sqlite在我的数据库中创建3个表,我通过抽屉导航在片段之间导航, DVD表适用于CD表 我有一个错误:引起:SQL(查询)错误或丢失数据库。 (没有这样的表:CD(代码1):,编译时:SELECT * FROM CD)
dbhelper = new SQLiteOpenHelper(getActivity(), "abbes5.db", null, 1) {
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("Create table DVD (_id INTEGER PRIMARY KEY NOT NULL , nom TEXT )");
db.execSQL("Create table CD (_id INTEGER PRIMARY KEY NOT NULL , nom TEXT )");
db.execSQL("Create table Livre (_id INTEGER PRIMARY KEY NOT NULL , nom TEXT )");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
};
Fragment dvd
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment2, container, false);
dbhelper = new SQLiteOpenHelper(getActivity(),"abbes5.db", null, 1) {
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("Create table DVD (_id INTEGER PRIMARY KEY NOT NULL , nom TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
};
listview= (ListView) rootView.findViewById(R.id.listView);
recherche = (EditText) rootView.findViewById(R.id.recherche);
db = dbhelper.getReadableDatabase();
Cursor c = db.rawQuery("SELECT * FROM DVD",null);
if(c.moveToFirst()){
c.moveToFirst();
String[] columns = new String[]{
"nom"
};
片段CD
dbhelper = new SQLiteOpenHelper(getActivity(),"abbes5.db", null, 1) {
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("Create table CD (_id INTEGER PRIMARY KEY NOT NULL , nom TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
};
listview1= (ListView) rootView.findViewById(R.id.listView1);
recherche1 = (EditText) rootView.findViewById(R.id.recherche1);
db = dbhelper.getReadableDatabase();
Cursor c = db.rawQuery("SELECT * FROM CD", null);
if(c.moveToFirst()){
c.moveToFirst();
String[] columns = new String[]{
"nom"
};
答案 0 :(得分:0)
使用类似的东西
db.query("CD",rest of all parameter null);
这将像您查询一样工作