Alright so I have been researching for the past day and I cannot seem to figure out what the heck is wrong with my code. I have compared my syntax to a ton of different sources and I still get errors when attempting to insert information into my row. The database is for a simple registration page where I retrieve the username and the password and insert them into my database. Code:
public static final int database_version = 1;
public String CREATE_QUERY = " CREATE TABLE " + " ("+ TableData.TableInfo.USER_NAME +" TEXT, " + TableData.TableInfo.USER_PASS +" TEXT);";
public DatabaseOperations(Context context) {
super(context, TableData.TableInfo.DATABASE_NAME, null, database_version);
Log.d("Database operations", "Database created");
}
@Override
public void onCreate(SQLiteDatabase sdb){
sdb.execSQL(CREATE_QUERY);
Log.d("Database operations", "Table created");
}
@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2)
{
}
public void putInformation(DatabaseOperations dop,String name,String pass)
{
SQLiteDatabase SQ = dop.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(TableData.TableInfo.USER_NAME, name);
cv.put(TableData.TableInfo.USER_PASS, pass);
SQ.insert(TableData.TableInfo.TABLE_NAME,null,cv);
Log.d("Database operations", "One row inserted");
}
The errors I get look like this:
03-22 19:09:45.300 31883-31883/com.example.andy.justalk E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.andy.justalk, PID: 31883
android.database.sqlite.SQLiteException: near "(": syntax error (code 1): , while compiling: CREATE TABLE (user_name TEXT, user_pass TEXT);
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
I was actually getting past the registration page before but even then when I would attempt to log in it would say that there was no user_pass column created. I know there are a ton of these types of questions out there I just cannot seem to see anything wrong with my code. I even asked a professor and he said my query looked fine. Any suggestions?! Am I missing a space or something somewhere!?!?!?!
Aucun commentaire:
Enregistrer un commentaire