0

I am using datbase to store group details and contact info in the database,but whenever i insert some data in to database i get error saying "no such table".What wrong i have done??

Code

public class GroupDataBase extends SQLiteOpenHelper {

    private static final int dbVersion = 1;
    private static final String dbName = "HSsuraksha";
    private static final String tableName = "groupDetails";
    private static final String groupId = "groupId";
    private static final String groupName = "groupName";
    private static final String createdOn = "createdOn";
    private static final String createTable = "CREATE TABLE " + tableName + "(" + groupId + " Integer Primary Key Auto Increment," + groupName + " Text," + createdOn + " Text" + ")";


    public GroupDataBase(Context context) {
        super(context, dbName, null, dbVersion);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {

        sqLiteDatabase.execSQL(createTable);

    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i2) {

    }


    public void insertGroupDetails(GroupModel groupModel) {
        SQLiteDatabase database = getWritableDatabase();
        database.beginTransaction();
        ContentValues contentValues = new ContentValues();
        contentValues.put(groupName, groupModel.getGroupName());
        contentValues.put(createdOn, groupModel.getGroupCreatedDate());
        if (contentValues != null) {

            Long id = database.insert(tableName, null, contentValues);
            Log.e("Group insert values", "" + id);

        }
        database.setTransactionSuccessful();
        database.endTransaction();
        database.close();

    }


}

LOGCAT

08-01 12:57:26.129    2522-2522/example.com.pocketdocs E/SQLiteLog﹕ (1) no such table: groupDetails
08-01 12:57:26.129    2522-2522/example.com.pocketdocs E/SQLiteDatabase﹕ Error inserting createdOn=2014-08-01 groupName=test
    android.database.sqlite.SQLiteException: no such table: groupDetails (code 1): , while compiling: INSERT INTO groupDetails(createdOn,groupName) VALUES (?,?)
            at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
            at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:893)
            at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:504)
            at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
            at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
            at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
            at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1475)
            at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1347)
            at example.com.pocketdocs.DataBase.GroupDataBase.insertGroupDetails(GroupDataBase.java:50)
            at example.com.pocketdocs.Group.CreateNewGroup.onClick(CreateNewGroup.java:87)
            at android.view.View.performClick(View.java:4147)
            at android.view.View$PerformClick.run(View.java:17161)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:213)
            at android.app.ActivityThread.main(ActivityThread.java:4787)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
            at dalvik.system.NativeStart.main(Native Method)
08-01 12:57:26.129    2522-2522/example.com.pocketdocs E/Group insert values﹕ -1

Do i have written the create table query wrong????

1
  • (Default comment): logcat please Commented Aug 1, 2014 at 7:33

3 Answers 3

1

You have a syntax error in your CREATE TABLE: There should be no space between auto and increment.

Since you're not seeing an exception about it, your onCreate() has not been run in its current form.

Sign up to request clarification or add additional context in comments.

4 Comments

thankyou very much it worked.Sir i have another doubt can you help me solve it out?
If you have another question, feel free to post it as a question.
can we have a discussion chat??
Accept this as an answer and post a new question.
1

instead of your table creation query use following

private static final String createTable = "CREATE TABLE " + tableName + "(" + groupId + " Integer Primary Key Autoincrement," + groupName + " Text," + createdOn + " Text" + ")";

i think problem in "auto increment" it should be together.

Comments

0

change your line to this

private static final String createTable = "CREATE TABLE " + tableName + "(" + groupId + " Integer Primary Key Autoincrement," + groupName + " Text," + createdOn + " Text" + ");";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.