我正在研究一个Sqlite Sample.although我在样本中完全做同样的事情(mybe not)。我在下面得到了这个例外。所以我检查了mycolumnName“KEY_Pass”并且它存在但是eclips说我的专栏名称“通过”。我知道。这可能是一个愚蠢的问题。但真的需要你的帮助。我无法弄清楚自己
table users has no column named pass
while compiling: INSERT INTO users(pass,name) VALUES (?,?
while compiling: SELECT name, id, pass FROM users
这是我的代码
public class MydatabaseClass {
private static final String DatabaseName="mydb";
private static final String TableName="users";
private static final int version=1;
private static final String KEY_Username="name";
private static final String KEY_Pass="pass";
private static final String KEY_Id="id";
SQLiteDatabase ourdatabase;
Context ourContext;
myHelper ourhelper;
public MydatabaseClass(Context con){
ourContext=con;
}
public MydatabaseClass OpenDB(){
ourhelper=new myHelper(ourContext);
ourdatabase=ourhelper.getWritableDatabase();
return this;
}
public MydatabaseClass CloseDb(){
ourhelper.close();
return this;
}
public void addthat(String name,String password){
ContentValues cv=new ContentValues();
cv.put(KEY_Username, name);
cv.put(KEY_Pass, password);
ourdatabase.insert(TableName, null, cv);
}
public String getThat(){
String[] columns={KEY_Username,KEY_Id,KEY_Pass};
Cursor cursor=ourdatabase.query(TableName, columns, null, null, null, null, null);
int rowID=cursor.getColumnIndex(KEY_Id);
int uName=cursor.getColumnIndex(KEY_Username);
int pass=cursor.getColumnIndex(KEY_Pass);
String str="";
for (cursor.moveToFirst();!cursor.isAfterLast();cursor.moveToNext()){
str=str+"Name :"+cursor.getString(uName)+"Pass :"+cursor.getString(pass);
}
return str;
}
public class myHelper extends SQLiteOpenHelper{
String query="CREATE TABLE "+TableName+"("
+ KEY_Id+" INTEGER PRIMARY KEY AUTOINCREMENT , "+KEY_Username+" TEXT NOT NULL, "
+KEY_Pass +" TEXT NOT NULL);";
public myHelper(Context context) {
super(context, DatabaseName, null, version);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(query);
}
答案 0 :(得分:0)
此表达式
KEY_Pass ="通过&#34 ;;
表示KEY_Pass是列的Java名称,该字段的SQL名称是" pass"。您需要创建一个字段名称为pass的表,而不是KEY_Pass。