3

I have three tables in my db. i try out many sample regarding creating db in sqlite, and it works out find most of them is one table only....

I try many ways like execute queries db.execSQL(query) to create each table in onCreate but it errors ..

SO Any good strategies to create more than one table??? should i create many class represent for each table extends SQLiteOpenHelper???

Thx

here is part of my class extends SQLiteOpenHelper

public void onCreate(SQLiteDatabase db) {
    // TODO Auto-generated method stub
    try{
        db.execSQL(CREATE_TABLE_1);
        db.execSQL(CREATE_TABLE_2);
        db.execSQL(CREATE_TABLE_3);
    }catch( Exception e){
        Log.e("dbAdapter", e.getMessage().toString());
    }

}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_1);
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_2);
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_3);
    onCreate(db);
}

it seems the table2, and table3 not create cuz when i insert data into table 2 i get error - no such table2 found !!!

here my created table string:

//create script patient
public static String CREATE_TABLE_1= "create table " +
TABLE_USER + " (" +
USER_ID + " integer primary key autoincrement, " +
USER_NAME + " text not null, " +
DEVICE_KEY + " text not null  );" ;

public static String CREATE_TABLE_2= "create table " +
TABLE_GPS_SETTING + " (" +
SETTIN + " integer primary key autoincrement, " +
REFRESVAL + " long not null, " +
ODE + " varchar(20), " +
_TYPE + " varchar(20) );" ;

public static String CREATE_TABLE_3= "create table " +
TABLE_W + " (" +
GPD + " integer primary key autoincrement, " +
LITUDE + " double, " +
LITUDE + " double, " + 
ATUDE + "integer,"+
M + "integer,"+
DTION + "integer,"+
DANCE + "integer,"+
LDD + "integer,"+
SESID + "double,"+
ACCCY + "double,"+
TMP + "long,"+
TATE + "TEXT,"+
D_ID + "TEXT);" ;

Any idea?

3
  • What errors do you get? What do your sql statements look like? Provide this in your question. We cannot guess these things. Commented Jul 21, 2011 at 8:34
  • it's not really error in app cuz i just need to create table in my db in sqlite but it create only the 1st table table1 n no table 2 n 3 WHY? thx Commented Jul 21, 2011 at 8:48
  • You see? Provide a good question and it will be easier to provide good answers ;) Commented Jul 21, 2011 at 9:41

2 Answers 2

5

I believe there is no such thing as a varchar in SQLite. Use text.

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

1 Comment

@sayvortana - that's life sometimes :) ...remember to mark the correct answer!
4

You can create as many table as you want like this.

 db.execSQL(TABLE1);
 db.execSQL(TABLE2);

where TABLE1 is the string containing table creation command

Problem is you are trying to create table after creating the database.Uninstall your application and then run with the sql statements to create tables in the database.

2 Comments

can u look the question that i just edit cuz i already did so
Problem is in your field type.See supported column type in sqlite sqlite.org/datatype3.html

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.