0

我必须启动一个使用 1 个数据库表(ABezoe)的应用程序我想向数据库添加一个额外的表(ABezur)

我试图让一个类与 ABezoe 类相似,但我得到一个错误,它无法找到第二个(ABezur)表,所以我无法写入它

所以互联网上的搜索告诉我我需要一个类(ADbAdapter)来创建我的数据库,并且为我想要连接到的不同表(ABezoeAdapter,ABezurAdapter)有不同的类会很好

我已尽一切努力尝试此设置,但仍然无法正常工作

我什至删除了应用程序以重新安装所有内容,但仍然没有调用数据库的 oncreate()

谁能帮我?

logcat 显示:

09-15 13:50:47.063: E/SQLiteLog(855): (1) no such table: ABezoe
09-15 13:50:47.253: E/SQLiteDatabase(855): Error inserting Z28=X RECNUM=2 Z04=0                Z05=13333333 Z02=2013-09-15 13:50 Z03=O Z00=1 Z17=J Z07=onbekendenstraat Z18=0909 Z06=onbekend Z19=1234 Z09=0 Z08=99999 Z25=131213 Z13=clarkie Z24=0 Z14=c99 Z27= Z15=sn9999 Z26=12345 Z16=0 Z21=99999 Z20=X Z10=9999 Z23=9999 Z11=9191 Z22=J Z12=kweniegem
09-15 13:50:47.253: E/SQLiteDatabase(855): android.database.sqlite.SQLiteException: no such table: ABezoe (code 1): , while compiling: INSERT INTO ABezoe(Z28,RECNUM,Z04,Z05,Z02,Z03,Z00,Z17,Z07,Z18,Z06,Z19,Z09,Z08,Z25,Z13,Z24,Z14,Z27,Z15,Z26,Z16,Z21,Z20,Z10,Z23,Z11,Z22,Z12) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)

09-15 13:50:47.303: E/SQLiteLog(855): (1) no such table: ABezur
09-15 13:50:47.344: E/SQLiteDatabase(855): Error inserting Z05=2013-09-15 13:50 Z02=5     Z03=13:50 Z01=null
09-15 13:50:47.344: E/SQLiteDatabase(855): android.database.sqlite.SQLiteException: no such table: ABezur (code 1): , while compiling: INSERT INTO ABezur(Z05,Z02,Z03,Z01) VALUES (?,?,?,?)

除此之外,在 logcat 中没有什么特别的

我需要创建数据库的 ADbAdapter 类:

   package com.example.deceunincktechniekers;

    import android.content.Context;
    import android.database.SQLException;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class ADbAdapter {
    public static final String databasenaam = "ATribune";

    public static final int databaseversie = 2;



private static final String CREATE_TABEL_ABEZOE = "CREATE TABLE " + 
            ABezoeAdapter.databasetabel + "(" +
            ABezoeAdapter.recordnummer + " BLOB NOT NULL, " +
            ABezoeAdapter.bezoekrapportnummer + " INTEGER PRIMARY KEY AUTOINCREMENT, " +

            //**here are some lines deleted**//

            ABezoeAdapter.verzonden + " VARCHAR(1) NOT NULL );";

private static final String CREATE_TABEL_ABEZUR = "CREATE TABLE " + 
            ABezurAdapter.databasetabel + "(" +
            ABezurAdapter.recordnummer + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
            ABezurAdapter.bezoekrapportnummer + " VARCHAR(10) NOT NULL, " +
            ABezurAdapter.werknemer + " VARCHAR(3) NOT NULL, " +
            ABezurAdapter.begintijd + " VARCHAR(4) NOT NULL, " +
            ABezurAdapter.eindtijd + " VARCHAR(4) NOT NULL, " +
            ABezurAdapter.datum + " DATETIME NOT NULL, " +
            ABezurAdapter.ONBEKEND + " VARCHAR(2) NOT NULL, " +
            ABezurAdapter.totaaltijd + " VARCHAR(4) NOT NULL );";

            private Context context; 
            private DatabaseHelper DBHelper;
            private SQLiteDatabase db;


    public void DBAdapter(Context ctx)
    {
        this.context = ctx;
        this.DBHelper = new DatabaseHelper(this.context);
    }

    private static class DatabaseHelper extends SQLiteOpenHelper 
    {
        DatabaseHelper(Context context) 
        {
            super(context, databasenaam, null, databaseversie);
        }

        @Override
        public void onCreate(SQLiteDatabase db) 
        {
            db.execSQL(CREATE_TABEL_ABEZOE);  
            db.execSQL(CREATE_TABEL_ABEZUR); 
            Log.i("oncreate databases geroepen", "oncreate werkt" );
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, 
        int newVersion) 
        {               
            db.execSQL("DROP TABLE IF EXISTS " + ABezoeAdapter.databasetabel);
            onCreate(db);
        }
    }; 


    public ADbAdapter open() throws SQLException 
    {
        this.db = this.DBHelper.getWritableDatabase();
        return this;
    }

    public void close() 
    {
        this.DBHelper.close();
    }
}

ABezurAdapter 类:

package com.example.deceunincktechniekers;

import android.content.ContentValues;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class ABezurAdapter extends ADbAdapter {
    public static final String recordnummer = "RECNUM";
    public static final String bezoekrapportnummer = "Z01";
    public static final String werknemer = "Z02";
    public static final String begintijd = "Z03";
    public static final String eindtijd = "Z04";
    public static final String datum = "Z05";
    public static final String ONBEKEND = "Z06";
    public static final String totaaltijd = "Z07";

    //private static final String databasenaam = "ATribune";
    public static final String databasetabel = "ABezur";
    //private static final int databaseversie = 1;

    private dbhulp onzehelper;
    private final Context onzecontext;
    private SQLiteDatabase onzedatabase;    

    public static class dbhulp extends SQLiteOpenHelper
    {

        public dbhulp(Context context) {
            super(context, ADbAdapter.databasenaam, null, ADbAdapter.databaseversie);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        }



    }
    public ABezurAdapter(Context c){
        onzecontext = c;
    }

    public ABezurAdapter open() throws SQLException{
        onzehelper = new dbhulp(onzecontext);
        onzedatabase = onzehelper.getWritableDatabase();
        return this;
    }

    public void sluit(){
        onzehelper.close();

    }

    public long startwerkuren(String bezoeknummer, int werknemer2,
            String starttijd, String datum2) {


        ContentValues cv = new ContentValues();
        cv.put(bezoekrapportnummer, bezoeknummer);
        cv.put(datum, datum2);
        cv.put(begintijd, starttijd);
        cv.put(werknemer, werknemer2);



        return onzedatabase.insert(databasetabel, null, cv);



    }
4

0 回答 0