I am creating my first Android application and I am having problems creating a second table in my database.
This is my code:
(DatabaseHelper.java)
public class DataBaseHelper extends SQLiteOpenHelper { public DataBaseHelper(Context context, String name,CursorFactory factory, int version) { super(context, name, factory, version); }
(DatabaseFunc.java)
public class DatabaseFunc { static final String DATABASE_NAME = "login.db"; static final int DATABASE_VERSION = 1; public static final int NAME_COLUMN = 1; // TODO: Create public field for each column in your table. // SQL Statement to create a new database. static final String DATABASE_CREATE = "create table "+"LOGIN"+ "( " +"ID"+" integer primary key autoincrement,"+ "USERNAME text,PASSWORD text, TEAMID text) "; static final String DATABASE_CREATE2 = "create table "+"SMSREG"+"" + "( " +"ID"+" integer primary key autoincrement,"+ "TONUM text, MESSAGE text, SUCCESS text) "; // Variable to hold the database instance public SQLiteDatabase db; // Context of the application using the database. private final Context context; // Database open/upgrade helper private DataBaseHelper dbHelper; public DatabaseFunc(Context _context) { context = _context; dbHelper = new DataBaseHelper(context, DATABASE_NAME, null, DATABASE_VERSION); } public DatabaseFunc open() throws SQLException { db = dbHelper.getWritableDatabase(); return this; } public void close() { db.close(); } public SQLiteDatabase getDatabaseInstance() { return db; } public void insertEntry(String userName,String password) { ContentValues newValues = new ContentValues(); // Assign values for each row. newValues.put("USERNAME", userName); newValues.put("PASSWORD",password); newValues.put("TEAMID", "0"); // Insert the row into your table db.insert("LOGIN", null, newValues); ///Toast.makeText(context, "Reminder Is Successfully Saved", Toast.LENGTH_LONG).show(); } public void insertNewSMS(String SMSNumber, String Message, String Success) { ContentValues SMSPut = new ContentValues(); SMSPut.put("TONUM", SMSNumber); SMSPut.put("MESSAGE", Message); SMSPut.put("SUCCESS", Success); db.insert("SMSREG", null, SMSPut); } public String DisplaySMS() { String tempholder = ""; Cursor cursor1=db.query(false, "SMSREG", null, null, null, null, null, null, null); cursor1.moveToFirst(); while (cursor1.isAfterLast() == false) { tempholder += ""+ cursor1.getString(cursor1.getColumnIndex("TONUM")) + ":@ FIELDSEP@ :" + cursor1.getString(cursor1.getColumnIndex("MESSAGE")) + ":@ FIELDSEP@ :" + cursor1.getString(cursor1.getColumnIndex("SUCCESS")) + ":@ ROWSEP@ :"; cursor1.moveToNext(); } cursor1.close(); return tempholder; } public int deleteEntry(String UserName) { //String id=String.valueOf(ID); String where="USERNAME=?"; int numberOFEntriesDeleted= db.delete("LOGIN", where, new String[]{UserName}) ; // Toast.makeText(context, "Number fo Entry Deleted Successfully : "+numberOFEntriesDeleted, Toast.LENGTH_LONG).show(); return numberOFEntriesDeleted; } public String getSinlgeEntry() { Cursor cursor=db.query(false, "LOGIN", null, null, null, null, null, null, null); if(cursor.getCount()<1) // UserName Not Exist { cursor.close(); return "NOT EXIST"; } cursor.moveToFirst(); String password= cursor.getString(cursor.getColumnIndex("PASSWORD")); String username= cursor.getString(cursor.getColumnIndex("USERNAME")); String teamids = cursor.getString(cursor.getColumnIndex("TEAMID")); cursor.close(); return username + ":@ SEP@ :" + password + ":@ SEP@ :" + teamids; } public void updateEntry(String userName,String password) { // Define the updated row content. ContentValues updatedValues = new ContentValues(); // Assign values for each row. updatedValues.put("USERNAME", userName); updatedValues.put("PASSWORD",password); updatedValues.put("TEAMID", "0"); String where="USERNAME = ?"; db.update("LOGIN",updatedValues, null, null); } public void updateTeamID(String TeamID) { // Define the updated row content. ContentValues updatedValuesa = new ContentValues(); // Assign values for each row. updatedValuesa.put("TEAMID", TeamID); db.update("LOGIN",updatedValuesa, null, null); } }
The login table works fine, it creates, the data falls into it in order, and it is extracted OK, but according to the SQLite editor available for the emulator, the SMSREG table is never created ... I hope someone can advise how I pulled my hair in for hours! :)
I tried adding and removing a half-line at the end of SQL statements, but that does not seem to matter.
Your help in advanced work will be greatly appreciated.