我有数据库应用程序
我想在进入数据库之前检查数据库中的数据
如果数据库中的数据相等则无法输入,如果数据不相等可以输入
这是我的一些代码:
public void saveData(){
long tim = System.currentTimeMillis();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss");
String curTime = df.format(tim);
Cursor c = helper.getNoOrder();
c.moveToFirst();
if(c.getCount() != 0){
System.out.println("klik");
if(noOrder.getText().toString().equals(c.getString(0))){
Toast.makeText(this, "No Order Sudah Terdaftar", Toast.LENGTH_LONG).show();
}else{
helper.insertBeli123(noOrder.getText().toString(), item.getText().toString(),
custName.getText().toString(), custTelp.getText().toString(),
qty.getText().toString(),temp.getText().toString(),temp.getText().toString(),
temp.getText().toString(), curTime);
Toast.makeText(this, "Data berhasil disimpan", Toast.LENGTH_LONG).show();
finish();
}
}else{
helper.insertBeli123(noOrder.getText().toString(), item.getText().toString(),
custName.getText().toString(), custTelp.getText().toString(),
qty.getText().toString(),temp.getText().toString(),temp.getText().toString(),
temp.getText().toString(), curTime);
Toast.makeText(this, "Data berhasil disimpan", Toast.LENGTH_LONG).show();
finish();
}
//startActivity(new Intent(this,Direktori.class));
}
在我的 DBhelper 中是这样的:
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE tanda_terima (_id integer primary key AUTOINCREMENT,no_order text " +
",item text,cust_id text,cust_name text,cust_telp text,quantity text,order_nik text" +
",pengirim text,penerima text,gambar text,waktu_ambil datetime,flag integer)");
db.execSQL("CREATE TABLE image (_id integer primary key AUTOINCREMENT,no_order text ,image text,tgl_buat datetime,flag integer)");
db.execSQL("CREATE TABLE user (user text primary key,no_imei integer,password text)");
db.execSQL("CREATE TABLE log_sync_tanda (no_order text primary key,status text ,waktu_sync datetime)");
db.execSQL("CREATE TABLE log_sync_image (image text primary key,kdstore text,status text ,waktu_sync datetime)");
}
public void insertBeli123(String no_order,String item,String cust_name
,String cust_telp,String quantity,String pengirim,String penerima,
String gambar,String waktu){
ContentValues cv = new ContentValues();
cv.put("no_order", no_order);
cv.put("item", item);
cv.put("cust_name", cust_name);
cv.put("cust_telp", cust_telp);
cv.put("quantity", quantity);
cv.put("pengirim", pengirim);
cv.put("penerima", penerima);
cv.put("gambar", gambar);
cv.put("waktu_ambil", waktu);
getWritableDatabase().insert("tanda_terima", "name", cv);
}
public Cursor getNoOrder(){
return(getReadableDatabase().rawQuery("SELECT no_order FROM tanda_terima", null));
}