使用準備好的語句我試圖插入值到表顯示電子郵件沒有列名稱,但很明顯,我沒有錯過我的項目中的任何地方的電子郵件。在連接到數據庫時在android中缺少字段
RegistrationAcitivity.java
public void reg_submit(View v){
DataHelper con=new DataHelper(this);
GetterRegistration model=new GetterRegistration();
SQLiteDatabase db = con.getWritableDatabase();
**String sql="insert into registration(name,email,password)values(?,?,?)";**
SQLiteStatement stmt = db.compileStatement(sql);
stmt.bindString(1, model.getName());
stmt.bindString(2, model.getEmail());
stmt.bindString(3, model.getPassword());
stmt.execute();
db.close();
Intent in = new Intent(this, CocomoActivity.class);
startActivityForResult(in, requestCode);
}
}
DataHelper.java
public class DataHelper extends SQLiteOpenHelper {
public static final String TABLE_COMMENTS = "registration";
public static final String id= "_id";
public static final String name = "name";
**public static final String email = "email";**
public static final String password = "password";
private static final String DATABASE_NAME = "mydb.db";
private static final int DATABASE_VERSION = 1;
// Database creation sql statement
private static final String DATABASE_CREATE = "create table "
+ TABLE_COMMENTS + "(" + id
+ " integer primary key autoincrement, " + name
+ " text not null,"+email
+"text not null," +password
+"text not null)";
這是logcat的
錯誤報告05-11 15:16:25.785:電子/ AndroidRuntime(704):at java.lang.reflect.Method.invoke(Method.java:507) 05- 11 15:16:25.785:E/AndroidRuntime(704):在android.view.View $ 1.onClick(View.java:2139) 05-11 15:16:25.785:E/AndroidRuntime(704):... 11更多 05-11 15:16:25.785:E/AndroidRuntime(704):引起:android.database.sqlite.SQLiteException:表註冊沒有列名爲電子郵件:,而編譯:插入註冊(名稱,電子郵件,密碼)值(?,?,?) 05-11 15:16:25.785:E/AndroidRuntime(704):at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method) 05-11 15:16 :25.785:E/AndroidRuntime(704):at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92) 05-11 15:16:25.785:E/AndroidRuntime(704):at android.database.sqlite .SQLiteCompiledSql。(SQLiteCompiledSql.java:65) 05-11 15:16:25.785:E/AndroidR (704):at android.database.sqlite.SQLiteProgram。(SQLiteProgram.java:83) 05-11 15:16:25.785:E/AndroidRuntime(704):at android.database.sqlite.SQLiteStatement。(SQLiteStatement。 java:41) 05-11 15:16:25.785:E/AndroidRuntime(704):at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1149) 05-11 15:16:25.785:E/AndroidRuntime(704):在android.cocomo.login.RegistrationActivity.reg_submit(RegistrationActivity.java:45)。
任何幫助將不勝感激。先謝謝你。仍然我試圖解決這個如果有人的建議讓我認識的朋友
泰塔倫Maheshwari之間。 zzz愚蠢的錯誤..什麼新手是我 – Praveenbabu
Wc .. plz接受答案.. – Tarun
'私人靜態最終字符串DATABASE_CREATE =「創建表」 \t \t + TABLE_COMMENTS +「(」+ ID +「整數主鍵自動增量,」+ name +「text not null」,+ email +「text not null」,+ password + \t \t \t「text not null)」;' – Praveenbabu