Could anyone tell me what's wrong. Previously it worked perfectly for one table "books" but now I'm creating a new database with 3 tables and it's not executing. Here's the helper class.
public class DatabaseHelper extends SQLiteOpenHelper{
private static final String DATABASE_NAME="MyDatabse1.db";
public DatabaseHelper(Context context)
{
super(context,DATABASE_NAME,null,1);
}
public void onCreate(SQLiteDatabase db)
{
db.execSQL("CREATE TABLE userdetails (_id INTEGER AUTOINCREMENT, username TEXT UNIQUE, password TEXT, name TEXT, phonenumber TEXT, address TEXT, fine INTEGER, bookid INTEGER, PRIMARY KEY (_id, username, password));");
db.execSQL("CREATE TABLE issue (_id INTEGER AUTOINCREMENT, book_id INTEGER UNIQUE, username TEXT, issue_date DATE, return_date DATE, PRIMARY KEY (_id, username, book_id));");
db.execSQL("CREATE TABLE bookstable (_id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, author TEXT, category TEXT, availability TEXT);");
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS userdetails");
db.execSQL("DROP TABLE IF EXISTS issue");
db.execSQL("DROP TABLE IF EXISTS bookstable");
onCreate(db);
}
And here's the stack trace
07-18 12:47:22.686: E/SQLiteLog(3423): (1) near "AUTOINCREMENT": syntax error
07-18 12:47:22.916: E/AndroidRuntime(3423): FATAL EXCEPTION: main
07-18 12:47:22.916: E/AndroidRuntime(3423): java.lang.IllegalStateException: Could not execute method of the activity
07-18 12:47:22.916: E/AndroidRuntime(3423): Caused by: android.database.sqlite.SQLiteException: near "AUTOINCREMENT": syntax error (code 1): , while compiling: CREATE TABLE userdetails (_id INTEGER AUTOINCREMENT, username TEXT UNIQUE, password TEXT, name TEXT, phonenumber TEXT, address TEXT, fine INTEGER, bookid INTEGER, PRIMARY KEY (_id, username, password));
07-18 12:47:22.916: E/AndroidRuntime(3423): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
07-18 12:47:22.916: E/AndroidRuntime(3423): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
07-18 12:47:22.916: E/AndroidRuntime(3423): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
07-18 12:47:22.916: E/AndroidRuntime(3423): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
07-18 12:47:22.916: E/AndroidRuntime(3423): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
07-18 12:47:22.916: E/AndroidRuntime(3423): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
07-18 12:47:22.916: E/AndroidRuntime(3423): at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1672)
07-18 12:47:22.916: E/AndroidRuntime(3423): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1603)
07-18 12:47:22.916: E/AndroidRuntime(3423): at com.example.libraryplus.DatabaseHelper.onCreate(DatabaseHelper.java:26)
07-18 12:47:22.916: E/AndroidRuntime(3423): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
07-18 12:47:22.916: E/AndroidRuntime(3423): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
07-18 12:47:22.916: E/AndroidRuntime(3423): at com.example.libraryplus.DatabaseHelper.add_books(DatabaseHelper.java:53)
07-18 12:47:22.916: E/AndroidRuntime(3423): at com.example.libraryplus.AddBooksActivity.addNewBooks(AddBooksActivity.java:42)
Aucun commentaire:
Enregistrer un commentaire