2015-04-27 28 views
-1

沒有這樣的表,我在android開發新的,我已經建立一個應用程序的登錄,當我在數據庫中創建另一個表它successfully..but運行,它給了我錯誤no such table:customizeformdetails and android.database.sqlite.SQLiteException: no such table: customizeformdetails (code 1): , while compiling: INSERT INTO customizeformdetails(JSON) VALUES (?)SQLite中的Android

我的代碼是:LoginDatabseAdapter

static final String DATABASE_NAME = "database"; 
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 IF NOT EXISTS"+"adminreg"+ 
     "(" +"AdminRegID"+" integer primary key autoincrement,"+ "Rest_name text,Contact_person_name text,Designation text,Contact_no text,Email_addr text,PASSWORD text,Address text); "; 
// Variable to hold the database instance 

static final String DATABASE_FEEDBACKFORM="CREATE TABLE IF NOT EXISTS"+"customizeformdetails"+ 
     "("+"CustomizeFormId"+" integer primary key autoincrement,"+"JSON text);"; 

public SQLiteDatabase db; 
// Context of the application using the database. 
private final Context context; 
// Database open/upgrade helper 
private DataBaseHelper dbHelper; 
public LoginDatabaseAdapter(Context _context) 
{ 
    context = _context; 
    dbHelper = new DataBaseHelper(context, DATABASE_NAME, null, DATABASE_VERSION); 
} 
public LoginDatabaseAdapter open() throws SQLException 
{ 
    db = dbHelper.getWritableDatabase(); 
    return this; 
} 
public void close() 
{ 
    db.close(); 
} 

public SQLiteDatabase getDatabaseInstance() 
{ 
    return db; 
} 

public void insertEntry(String Rest_name,String Contact_person_name,String Designation,String Contact_no,String Email_addr,String PASSWORD, String Address) 
{ 
    ContentValues newValues = new ContentValues(); 
    // Assign values for each row. 
    newValues.put("Rest_name", Rest_name); 
    newValues.put("Contact_person_name",Contact_person_name); 
    newValues.put("Designation",Designation); 
    newValues.put("Contact_no",Contact_no); 
    newValues.put("Email_addr",Email_addr); 
    newValues.put("PASSWORD",PASSWORD); 
    newValues.put("Address",Address); 

    // Insert the row into your table 
    db.insert("adminreg", null, newValues); 
    Toast.makeText(context, "Reminder Is Successfully Saved", Toast.LENGTH_LONG).show(); 
    Log.e("context", "Toast"); 
} 

public void insertCustomizeEntry(String json) 
{ 
    Log.e("Data Insert reached","yes"); 
    ContentValues newValues = new ContentValues(); 
    newValues.put("JSON",json); 
    db.insert("customizeformdetails", null, newValues); 
    Toast.makeText(context, "Data Is Successfully Saved", Toast.LENGTH_LONG).show(); 
    Log.e("context", "Toast"); 
    selectCustomizeEntry(); 

} 

public String selectCustomizeEntry() 
{ 
    Cursor cursor=db.rawQuery("SELECT * FROM customizeformdetails", null); 
    if(cursor.getCount()<1) // UserName Not Exist 
    { 
     cursor.close(); 
     return "NOT EXIST"; 
    } 

    cursor.moveToFirst(); 
    String customizeFormDetails= cursor.getString(cursor.getColumnIndex("JSON")); 
    Log.e("Data",customizeFormDetails); 
    return customizeFormDetails; 

} 

DatabseHelper.cs:

public DataBaseHelper(Context context, String name,SQLiteDatabase.CursorFactory factory, int version) 
{ 
    super(context, name, factory, version); 
} 
// Called when no database exists in disk and the helper class needs 
// to create a new one. 
@Override 
public void onCreate(SQLiteDatabase _db) 
{ 
    _db.execSQL("DROP TABLE IF EXISTS " + LoginDatabaseAdapter.DATABASE_FEEDBACKFORM); 
    _db.execSQL(LoginDatabaseAdapter.DATABASE_CREATE); 
    _db.execSQL(LoginDatabaseAdapter.DATABASE_FEEDBACKFORM); 

} 

請幫me..It已經採取了這麼多時間

回答

2

您的CREATE TABLE SQL Command是錯誤的。

static final String DATABASE_FEEDBACKFORM="CREATE TABLE IF NOT EXISTS "+" customizeformdetails "+ 
    "("+"CustomizeFormId"+" integer primary key autoincrement,"+" JSON text);"; 

添加空間Column NameColumn Type後也EXISTS和表名之間添加空間。

+0

ERROR在databsehelper類:非靜態字段DATABASE_FEEDBACKFORM不能是靜態上下文 – Vidhi

+0

謝謝你這麼多 – Vidhi

+0

我剛剛寫這一點,但仍然得到錯誤:沒有這樣的表customizeform--靜態最後絃樂DATABASE_FEEDBACKFORM =「CREATE TABLE如果不存在「+」customizeform「+ 」(「+」CustomizeId「+」integer primary key autoincrement,「+」JSON text,AdminId text,JSON_modified text);「; – Vidhi

1

您在CREATE TABLE SQL中有語法問題:例如,在EXISTS和表名之間缺少空格。由於您沒有提及任何拋出的異常,因此您的onCreate()中的SQL未執行。原因是數據庫文件已經存在。

  1. 修復語法問題。

  2. 卸載您的應用程序,以便舊數據庫文件被移除並且onCreate()將被再次調用。

+0

非常感謝你.. – Vidhi

+0

我剛剛寫了這個,但仍然出現錯誤:沒有這樣的表customizeform-- static final String DATABASE_FEEDBACKFORM =「CREATE TABLE IF NOT EXISTS」+「customizeform」+ 「(」+「CustomizeId」+ 「整數主鍵自動增量」+「JSON文本,AdminId文本,JSON_modified文本);」; – Vidhi