在android中连接到db时,表中缺少字段

时间:2012-05-11 10:06:03

标签: java android android-layout

使用预准备语句我试图在表格中插入值电子邮件中没有列名但很明显我在项目的任何地方都没有错过电子邮件。

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:E / 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:表注册没有名为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)。

任何帮助将不胜感激。先感谢您。如果有人建议,我仍然试图解决这个问题让我认识朋友

1 个答案:

答案 0 :(得分:2)

电子邮件和文字之间没有空格。

 **email+"text** not null," +...

以及密码和文字之间的