0

I am Working on Android SQLite . I am creating new table and trying to insert values in it. But it gives no column LastName when trying to insert the values.

Please help me . Please check below code.

String query3 = "create table if not exists " + "SIGNUPINFO" + " ("                                 + "FirstName TEXT," + "LastName TEXT," + "EmailID TEXT," + "Password TEXT,"
+ "Phone TEXT," +"Security TEXT);";

db.execSQL(query3);

String query5 = "INSERT INTO SIGNUPINFO" + " (FirstName,LastName,EmailID,Password,Phone,Security) " + "VALUES ('"
+ firstName + "','" +lastName+  "','" + emailID  + "','" +password+  "','" + phone+ "','" + "security" +"');";

db.execSQL(query5);
Yogesh Borhade
  • 694
  • 1
  • 10
  • 24
user3571631
  • 821
  • 3
  • 8
  • 19
  • Please. Show log error – Nguyễn Trung Hiếu Feb 14 '17 at 03:51
  • have you update your table without update your database version? try clear your app data and run again, maybe your table is not update – Linh Feb 14 '17 at 03:58
  • If you have root access, then try to pull out the .db file and see if the database has been successfully created. Use any DMBS tool and try to execute your query. Just ran the code you pasted and looks ok. – Dibzmania Feb 14 '17 at 04:09

2 Answers2

1

Please check refernce answer for same problem.May it will help you.

Well, If you are confindent about syntax for creating table, than it may happen when you add new column in your same table, for that...

1) Unistall from your device and run it again.

OR

2) Setting -> app -> ClearData

OR

3) Change DATABASE_NAME in your "DatabaseHandler" class ( I faced same problem. But I suuceed by changing DATABASE_NAME.)

OR

4) Change DATABASE_VERSION in your "DatabaseHandler" class (If you have added new column than it will upgrade autimatically)

public DatabaseHandler(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }
Community
  • 1
  • 1
Kush
  • 1,080
  • 11
  • 15
-2

put this code in application class and get database in externalstorage.

Then you can check column created or not in database table.

 public static void copyDataBase(Context mActivity) throws IOException {
        Log.d("tag", "Copy Database called");
        InputStream myInput = new FileInputStream(new File("/data/data/"
                + mActivity.getPackageName() + "/databases/"
                + "yourdb.sqlite"));
        File files = new File(Environment.getExternalStorageDirectory()
                + "/files/");
        files.mkdirs();
        String outFileName = Environment.getExternalStorageDirectory()
                + "/yourdb.sqlite";
        OutputStream myOutput = new FileOutputStream(outFileName);
        byte[] buffer = new byte[1024];
        int bufferLength;
        while ((bufferLength = myInput.read(buffer)) > 0) {
            myOutput.write(buffer, 0, bufferLength);
        }
        myOutput.flush();
        myOutput.close();
        myInput.close();
        Log.d("tag", "Copy Database Done");
    }

I hope its useful to you.

dipali
  • 10,966
  • 5
  • 25
  • 51