Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Android Data Persistence Using SQLite for Structured Data Creating a SQLite Table

ANOTHER CREATE STATEMENT

Next, add another create statement called CREATE_CAR_MODELS that is public static final. Give it a primary key called _id and a TEXT field called CAR_NAME. The primary key should autoincrement!

AutoSQLiteHelper.java
public class AutoSQLiteHelper extends SQLiteOpenHelper {
  public static final String COLUMN_COMPANY_NAME = "COMPANY_NAME";
  public static final String COLUMN_CAR_MODELS = "CAR_MODELS";

  public static final String CREATE_CAR_MAKERS = 
          "CREATE TABLE CAR_MAKERS (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_COMPANY_NAME + " TEXT)";


  public static final String CREATE_CAR_MODELS = 
          "CREATE TABLE CAR_MODELS (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_CREATE_CAR_MODELS + " TEXT)";

  @Override
  public void onCreate(SQLiteDatabase database) {
    database.execSQL(CREATE_CAR_MAKERS);
    database.execSQL(CREATE_CAR_MODELS);
  }
}

STILL GETTING A BUMMER,

4 Answers

Dan Johnson
Dan Johnson
40,533 Points

Looks like just a mix up with constants:

// COLUMN_CREATE_CAR_MODELS -> COLUMN_CAR_MODELS
"CREATE TABLE CAR_MODELS (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_CAR_MODELS + " TEXT)";

Everything else looks fine.

public class AutoSQLiteHelper extends SQLiteOpenHelper { public static final String COLUMN_COMPANY_NAME = "COMPANY_NAME"; public static final String COLUMN_CAR_MODELS = "CAR_MODELS";

public static final String CREATE_CAR_MAKERS = "CREATE TABLE CAR_MAKERS (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_COMPANY_NAME + " TEXT)";

public static final String CREATE_CAR_MODELS =

      "CREATE TABLE CAR_MODELS (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_CAR_MODELS + " TEXT)";

@Override public void onCreate(SQLiteDatabase database) { database.execSQL(CREATE_CAR_MAKERS); database.execSQL(CREATE_CAR_MODELS); } }

Dan Johnson
Dan Johnson
40,533 Points

Looks like I missed the value of COLUMN_CAR_MODELS the first time, it should be assigned "CAR_NAME" instead of "CAR_MODELS". You may want to rename the constant to reflect that though it won't matter either way.

GOT IT ANX......

public class AutoSQLiteHelper extends SQLiteOpenHelper { public static final String COLUMN_COMPANY_NAME = "COMPANY_NAME"; public static final String COLUMN_CAR_MODELS = "CAR_MODELS"; public static final String CAR_NAME = "CAR_NAME";

public static final String CREATE_CAR_MAKERS = "CREATE TABLE CAR_MAKERS (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_COMPANY_NAME + " TEXT)";

public static final String CREATE_CAR_MODELS = "CREATE TABLE CAR_MODELS (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + CAR_NAME + " TEXT)";

@Override public void onCreate(SQLiteDatabase database) { database.execSQL(CREATE_CAR_MAKERS); database.execSQL(CREATE_CAR_MODELS); } }

public class AutoSQLiteHelper extends SQLiteOpenHelper {

public static final String COMPANY_NAME = "COMPANY_NAME"; public static final String COLUMN_CAR_MODELS = "CAR_MODELS"; public static final String CAR_NAME = "CAR_NAME";

public static final String CREATE_CAR_MAKERS = "CREATE TABLE CAR_MAKERS (id INTEGER PRIMARY KEY AUTOINCREMENT,"+COMPANY_NAME+"TEXT)";

public static final String CREATE_CAR_MODELS = "CREATE TABLE CAR_MODELS (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + CAR_NAME +" TEXT)";

@Override public void onCreate(SQLiteDatabase database) { database.execSQL(CREATE_CAR_MAKERS); database.execSQL(CREATE_CAR_MODELS); } }