android SQLite
Database.java
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class database {
public static final String KEY_ROWID="_id";
public static final String KEY_NAME="u_name";
public static final String KEY_PAS="u_pas";
private static final String DB_NAME="app";
private static final String DB_TABLE="users";
private static final int DB_VERSION=1;
private Context ourContext;
private DBHelper ourHelper;
private SQLiteDatabase ourDatabase;
public database (Context context){
ourContext=context;
}
public class DBHelper extends SQLiteOpenHelper{
public DBHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE"+ DB_TABLE + "(" + KEY_ROWID + "INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_NAME + "TEXT NOT NULL," +KEY_PAS + "TEXT NOT NULL);");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXIST "+ DB_TABLE);
onCreate(db);
}
}
public database open(){
ourHelper=new DBHelper(ourContext);
ourDatabase=ourHelper.getWritableDatabase();
return this;
}
public database close(){
ourHelper.close();
return this;
}
public void addThat(String name, String pass) {
ContextValues c= new ContextValues();
c.put(KEY_NAME,name);
c.put(KEY_PAS,pass);
ourDatabase.insert(DB_TABLE,null,c);
}
}
bu kod kümesin ourDatabase.insert(DB_TABLE,null,c); satırında hata ile karşılaşıyoruz. c değişkenini tanımıyor.yardımcı olursanız çok sevirim şimdiden teşekkürler.