SQLite没有创建表。没有找到这样的表,列名不是forund

时间:2017-08-01 07:27:04

标签: java android sqlite android-sqlite

我正在尝试将数据存储到android的

的sqlite db中

DBHelper类

echo ($gender == 'Male') ? $wo['lang']['male'] : (($gender == 'Female') ? $wo['lang']['female'] : $wo['lang']['unspecified']);

我试着点击按钮

    public class DBHelper extends SQLiteOpenHelper {

    private static final String TAG = "DBHelper";

    private static final String  DATABASE_NAME   =   "DemoAppDB";
    private static final int DATABASE_VERSION    =   6;

    private static final String  TABLE_VISIT =   "visit";
    private static final String  TABLE_LIVE  =   "live";

    private static final String  COL_TIMESTAMP   =   "timestamp";
    private static final String  COL_LOCATION    =   "location";
    private static final String  COL_LATITUDE    =   "latitude";
    private static final String  COL_LONGITUDE   =   "longitude";

    private static final String  COL_VISIT_ID    =   "_id_visit";
    private static final String  COL_VISIT_DOC   =   "doctor";
    private static final String  COL_VISIT_REP   =   "representative";
    private static final String  COL_VISIT_TYPE  =   "vist_type";
    private static final String  COL_VISIT_ACCOMPLICE    =   "accomplice";
    private static final String  COL_VISIT_PRODUCT_NAME  =   "product";
    private static final String  COL_VISIT_GIVEAWAYS =   "giveaways";

    private static final String  COL_LIVE_ID     =   "_id_live";
    private static final String  COL_LIVE_REP    =   "representative";


    public DBHelper(Context context){
        super(context,DATABASE_NAME,null,DATABASE_VERSION);
    }


    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        Log.d(TAG, "onCreate: Creating dbs");
        createVisitTable(sqLiteDatabase);
        createLiveTable(sqLiteDatabase);
        Log.d(TAG, "onCreate: db created");
    }

    public void createVisitTable(SQLiteDatabase sqLiteDatabase){
        sqLiteDatabase.execSQL("DROP TABLE IF EXISTS "   +   TABLE_LIVE);

//        this.getTables();
        sqLiteDatabase.execSQL(
                "create table " +   TABLE_VISIT +
                        " ( " +   COL_VISIT_ID    +   "   integer primary key autoincrement, " +
                        COL_TIMESTAMP   +   " text, " +
                        COL_VISIT_DOC   +   " text, " +
                        COL_VISIT_TYPE  +   " text, " +
                        COL_VISIT_ACCOMPLICE    +   " text, " +
                        COL_VISIT_PRODUCT_NAME  +   " text, " +
                        COL_VISIT_GIVEAWAYS +   " text, " +
                        COL_LATITUDE    +   " text, " +
                        COL_VISIT_REP   +   " text, " +
                        COL_LONGITUDE    +   " text )"
        );

    }

    public void createLiveTable(SQLiteDatabase sqLiteDatabase){
        sqLiteDatabase.execSQL("DROP TABLE IF EXISTS "   +   TABLE_VISIT);
        sqLiteDatabase.execSQL(
                "create table " +   TABLE_LIVE +
                        " ( " +   COL_LIVE_ID    +   "   integer primary key autoincrement, " +
                        COL_TIMESTAMP   +   " text, " +
                        COL_LATITUDE    +   " text, " +
                        COL_LONGITUDE   +   " text, " +
                        COL_LIVE_REP    +   " text )"
        );
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
        Log.d(TAG, "onUpgrade: old : ["+i+"] new : ["+i1+"]");
        if (i >= i1){
            return;
        }

        Log.d(TAG, "onUpgrade: Dropping [" + TABLE_LIVE + "]");
        sqLiteDatabase.execSQL("DROP TABLE IF EXISTS "   +   TABLE_LIVE);
        Log.d(TAG, "onUpgrade: Dropping [" + TABLE_VISIT + "]");
        sqLiteDatabase.execSQL("DROP TABLE IF EXISTS "   +   TABLE_VISIT);
        Log.d(TAG, "onUpgrade: CREATING [" + TABLE_VISIT + "]");
        createVisitTable(sqLiteDatabase);
        Log.d(TAG, "onUpgrade: CREATING [" + TABLE_LIVE + "]");
        createLiveTable(sqLiteDatabase);
        Log.d(TAG, "onUpgrade: SUCCESSFULLY RECREATED ALL");
    }

    public boolean  insertRowInVisit(VisitCall  visitCall){
        Log.d(TAG, "insertRowInVisit: inserting row in visit");
        SQLiteDatabase  db  =   this.getWritableDatabase();
        Log.d(TAG, "insertRowInVisit: Writable db fetched");

        ContentValues   contentValues   =   new ContentValues();
        contentValues.put(COL_TIMESTAMP, String.valueOf(visitCall.getTimestamp()));
        contentValues.put(COL_VISIT_DOC,String.valueOf(visitCall.getDoctorName()));
        contentValues.put(COL_VISIT_TYPE,visitCall.getVisitType());
        contentValues.put(COL_VISIT_ACCOMPLICE,visitCall.getAccompliceName());
        contentValues.put(COL_VISIT_PRODUCT_NAME,visitCall.getProductName());
        contentValues.put(COL_VISIT_GIVEAWAYS,visitCall.getGiveaways());
        contentValues.put(COL_VISIT_REP,visitCall.getRepresentativeName());
        contentValues.put(COL_LATITUDE,String.valueOf(visitCall.getLocation().getLatitude()));
        contentValues.put(COL_LONGITUDE,String.valueOf(visitCall.getLocation().getLongitude()));
        Log.d(TAG, "insertRowInVisit: visit call object :  ["+visitCall.toString()+"]");
        db.insert(TABLE_VISIT,null,contentValues);
        return true;
    }

StackTrace:

DBHelper dbHelper    =   new DBHelper(CallFormActivity.this);
dbHelper.insertRowInVisit(visitCall);

我也尝试过更改DB的版本,尝试更改sql的格式并且仍然错误保持不变最初它给出了没有找到这样的表的错误,我已经尝试了在这个论坛上给出的所有可能的解决方案

1 个答案:

答案 0 :(得分:1)

  1. 您在创建{ ..., watch: { chartShown(nv) { if (nv) { // setup chart } else { // remove chart } } }, ... } 时放弃Error:Unsupported method: NativeArtifact.getRuntimeFiles(). The version of Gradle you connect to does not support that method. To resolve the problem you can change/upgrade the target version of Gradle you connect to. Alternatively, you can ignore this exception and read other information from the model. 。导致这个问题。 尝试以下代码并从'TABLE_VISIT''TABLE_LIVE'

    中删除两个DROP命令
    createVisitTable()