Sqlite插入问题

时间:2016-02-07 18:56:35

标签: java android sqlite

我在我的android程序中遇到错误需要帮助我新的android

2-07 23:41:03.052 7613-7613 / com.example.ks.doit E / SQLiteLog:(1)table table3没有名为name的列 02-07 23:41:03.052 7613-7613 / com.example.ks.doit E / SQLiteDatabase:插入名称时出错= alinf password = asifjiejf username = aksdjfiej 02-07 23:41:03.052 7613-7613 / com.example.ks.doit E / SQLiteDatabase:android.database.sqlite.SQLiteException:table table3没有名为name(code 1)的列:,编译时:INSERT INTO table3 (名称,密码,用户名)VALUES(?,?,?) 02-07 23:41:03.052 7613-7613 / com.example.ks.doit E / SQLiteDatabase:at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) 02-07 23:41:03.052 7613-7613 / com.example.ks.doit E / SQLiteDatabase:at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887) 02-07 23:41:03.052 7613-7613 / com.example.ks.doit E / SQLiteDatabase:at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498) 02-07 23:41:03.052 7613-7613 / com.example.ks.doit E / SQLiteDatabase:at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 02-07 23:41:03.052 7613-7613 / com.example.ks.doit E / SQLiteDatabase:at android.database.sqlite.SQLiteProgram。(SQLiteProgram.java:58) 02-07 23:41:03.052 7613-7613 / com.example.ks.doit E / SQLiteDatabase:at android.database.sqlite.SQLiteStatement。(SQLiteStatement.java:31) 02-07 23:41:03.052 7613-7613 / com.example.ks.doit E / SQLiteDatabase:at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469) 02-07 23:41:03.052 7613-7613 / com.example.ks.doit E / SQLiteDatabase:at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1341) 02-07 23:41:03.052 7613-7613 / com.example.ks.doit E / SQLiteDatabase:at com.example.ks.doit.sqlite_database.insertData(sqlite_database.java:34) 02-07 23:41:03.052 7613-7613 / com.example.ks.doit E / SQLiteDatabase:at com.example.ks.doit.Insertion $ 1.onClick(Insertion.java:54) 02-07 23:41:03.052 7613-7613 / com.example.ks.doit E / SQLiteDatabase:at android.view.View.performClick(View.java:5198) 02-07 23:41:03.052 7613-7613 / com.example.ks.doit E / SQLiteDatabase:at android.view.View $ PerformClick.run(View.java:21147) 02-07 23:41:03.052 7613-7613 / com.example.ks.doit E / SQLiteDatabase:at android.os.Handler.handleCallback(Handler.java:739) 02-07 23:41:03.052 7613-7613 / com.example.ks.doit E / SQLiteDatabase:at android.os.Handler.dispatchMessage(Handler.java:95) 02-07 23:41:03.052 7613-7613 / com.example.ks.doit E / SQLiteDatabase:at android.os.Looper.loop(Looper.java:148) 02-07 23:41:03.052 7613-7613 / com.example.ks.doit E / SQLiteDatabase:at android.app.ActivityThread.main(ActivityThread.java:5417) 02-07 23:41:03.052 7613-7613 / com.example.ks.doit E / SQLiteDatabase:at java.lang.reflect.Method.invoke(Native Method) 02-07 23:41:03.052 7613-7613 / com.example.ks.doit E / SQLiteDatabase:at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726) 02-07 23:41:03.052 7613-7613 / com.example.ks.doit E / SQLiteDatabase:at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 02-07 23:41:03.130 7613-7638 / com.example.ks.doit W / EGL_emulation:eglSurfaceAttrib未实现 02-07 23:41:03.130 7613-7638 / com.example.ks.doit W / OpenGLRenderer:无法在表面0xabe82e60上设置EGL_SWAP_BEHAVIOR,错误= EGL_SUCCESS 02-07 23:41:06.575 7613-7638 / com.example.ks.doit E / Surface:getSlotFromBufferLocked:unknown buffer:0xab84f230 02-07 23:48:30.318 7613-7619 / com.example.ks.doit W / art:暂停所有线程:9.032ms

//this is my Sqlite class code
public boolean insertData(String name, String userName, String password)
    {
        SQLiteDatabase mydatabase = helper.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put(Helper.NAME,name);
        contentValues.put(Helper.USERNAME,userName);
        contentValues.put(Helper.PASSWORD, password);
        long result = mydatabase.insert(Helper.TABLE_NAME,null,contentValues);
        if (result <= 0)
        {
            return false;
        }
        else
        {
            return true;
        }
    }

class Helper extends SQLiteOpenHelper
    {

        //database information
        private static final String DATABASE_NAME="mydatabase3";
        private static final int DTABASE_VERSION=11;
        //table information
        private static final String TABLE_NAME="table3";
        private static final String NAME="name";
        private static final String USERNAME="username";
        private static final String PASSWORD="password";

        Context context;
        public Helper(Context context) {
            super(context,DATABASE_NAME, null, DTABASE_VERSION);
            this.context = context;
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            String CREATE_TABLE=
                    "CREATE TABLE"+
                            " "+Helper.TABLE_NAME+" "+
                            "("
                            +Helper.NAME+"TEXT,"
                            +Helper.USERNAME+"TEXT,"
                            +Helper.PASSWORD+"TEXT);";
            db.execSQL(CREATE_TABLE);
            Toast.makeText(context, "database create", Toast.LENGTH_LONG).show();
        }

1 个答案:

答案 0 :(得分:2)

您需要在列数据类型之前添加空格。

试试这个:

         *data1.count() - 9.5 sec*

         *data2.count() - 1.2 sec*