Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

android - error as "No such table" while inserting data in to table

Getting Error as NO such table,Table is not creating,Please help me with your answers.I think error is database.java file.So I uploaded it.In inserting values I am not changing fields of phone number into long...As I taken it as TEXT datatype in Database file. '

               public class MyDatabase extends SQLiteOpenHelper {

          Context c;

         // Database Name
           public static final String DATABASE_NAME = "BIRLA_ACCOUNTS";
        //Table Name
        public static final String TABLE_NAME = "MASTERACCOUNTS";
        //  Table Columns names
        public static final String CODE = "CODE";
        public static final String NAME = "NAME";
        public static final String TYPE = "TYPE";
        public static final String ADD1 = "ADD1";
        public static final String ADD2 = "ADD2";
        public static final String CITY = "CITY";
        public static final String COUNTRY = "COUNTRY";
        public static final String PHONENO = "PHONENO";
        public static final String CONTACTPERSON = "CONTACTPERSON";
         public static final String EMAILID = "EMAILID";
        public static final String FAX = "FAX";
         public static final String TNO = "TNO";
        public static final String CSTNO = "CSTNO";
        public static final String GSTNO = "GSTNO";
        public static final String SERVICENO = "SERVICENO";

        public MyDatabase(Context context) {
        super(context, DATABASE_NAME, null, 1);
        c = context;

       }

         @Override
          public void onCreate(SQLiteDatabase db) {
          try {

            db.execSQL("CREATE TABLE "+TABLE_NAME+"("+CODE+" INTEGER                                                                                                                                                                                                                                   
                     AUTOINCREMENT,"+NAME+" TEXT PRIMARY KEY ,"+TYPE+" TEXT,  
                       "+ADD1+" TEXT,"+ADD2+" TEXT,"+CITY+" TEXT,"+COUNTRY+                                                                                                                                                                                 
                          " TEXT,"+PHONENO+" TEXT,"
                    +CONTACTPERSON+" TEXT,"+EMAILID +" VARCHAR(50),"+FAX+" 
                        REAL,"+TNO+" REAL,"+CSTNO+" REAL,"+GSTNO+" REAL,"                                                                                                                          
            +SERVICENO +" REAL)");
              Toast.makeText(c, "Table Created", Toast.LENGTH_SHORT).show();
                    } catch (Exception e) {
                  Log.e("AccountsMaster creation", "" + e);
                       }


                  }

               @Override
          public void onUpgrade(SQLiteDatabase db, int oldVersion,
                   int  newVersion) {
            // Drop older table if existed
                db.execSQL("DROP TABLE IF EXISTS" + TABLE_NAME);
             // Creating tables again
                 onCreate(db);
              }

`

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Rectify Your Query . Aware from Blank Space and Single-Double Quote .

 "CREATE TABLE " + TABLE_NAME + " ("
                    + CODE + " INTEGER AUTOINCREMENT ," 
                    + NAME + " TEXT PRIMARY KEY ,"
                    + TYPE + " TEXT ,"
                    + ADD1 + " TEXT ,"
                    + ADD2 + " TEXT ,"
                    + CITY + " TEXT ,"
                    + COUNTRY + " TEXT ,"
                    + PHONENO + " TEXT ,"
                    + CONTACTPERSON + " TEXT ,"
                    + EMAILID + " VARCHAR(50) ,"
                    + FAX + " REAL ,"
                    + TNO + " REAL ,"
                    + CSTNO + " REAL ,"
                    + GSTNO + " REAL ,"
                    + SERVICENO + " REAL" + ")";

FYI

Use INTEGER PRIMARY KEY AUTOINCREMENT in CODE Field

 + CODE + " INTEGER PRIMARY KEY AUTOINCREMENT ," 
 + NAME + " TEXT ,"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...