使用准备好的语句,我尝试将值插入表中,显示电子邮件中没有列名,但很明显我没有错过项目中任何地方的电子邮件。
注册活动.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);
}
}
数据助手.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: E/AndroidRuntime(704): 在 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:表注册没有名为email的列,编译时:插入注册(名称,电子邮件,密码)值(?,?,?) 05-11 15:16:25.785: E/AndroidRuntime(704): 在 android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method) 05-11 15:16:25.785: E/AndroidRuntime(704): 在 android.database .sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92) 05-11 15:16:25.785: E/AndroidRuntime(704): 在 android.database.sqlite.SQLiteCompiledSql.(SQLiteCompiledSql.java:65) 05-11 15: 16:25.785: E/AndroidRuntime(704): 在 android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:83) 05-11 15:16:25.785: E/AndroidRuntime(704): 在 android.database.sqlite。 SQLiteStatement.(SQLiteStatement.java:41) 05-11 15:16:25.785: E/AndroidRuntime(704): 在 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)。
任何帮助将不胜感激 。先感谢您。如果有人建议让我知道朋友,我仍然在尝试解决这个问题