Значения не получают вставку в запрос базы данных возвращающий ложное значение
package com.example.puja.pizzahut; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Build; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.EditText; import android.widget.TextView; import android.widget.TimePicker; import android.widget.Toast; public class PizzaDetailSubActivity extends AppCompatActivity { EditText qty; TimePicker timePicker2; InsertDatabaseHandler db; TextView datalayoutaddress; String registeration_name,registeration_username,registeration_password,registeration_phone,pizza_name1,pizza_price,mode_of_trnf,reg_address,time_,reg_qty; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pizza_detail_sub); Bundle bundle=getIntent().getExtras(); registeration_name=bundle.getString("name"); registeration_username=bundle.getString("username"); registeration_password=bundle.getString("password"); registeration_phone=bundle.getString("phone"); pizza_name1=bundle.getString("pizza_name"); pizza_price=bundle.getString("pizza_price"); mode_of_trnf=bundle.getString("mode_of_trnf"); db=new InsertDatabaseHandler(this); timePicker2=(TimePicker)findViewById(R.id.timePicker2); datalayoutaddress=(TextView)findViewById(R.id.address); qty=(EditText)findViewById(R.id.qty); } public void onClickBuyNow(View view) { reg_address = datalayoutaddress.getText().toString(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { time_ = timePicker2.getHour() + ":" + timePicker2.getMinute(); reg_qty = qty.getText().toString(); System.out.println("Buy Time:" + timePicker2.getHour() + ":" + timePicker2.getMinute()); System.out.println(registeration_name + registeration_username + registeration_password + registeration_phone + pizza_name1 + pizza_price + mode_of_trnf + reg_address + time_ + reg_qty); boolean result = db.insertCustRecord(registeration_name,registeration_phone,pizza_name1,pizza_price,mode_of_trnf,reg_address,time_,reg_qty); System.out.println(result); startActivity(new Intent(this,ViewCart.class)); if (result == true){ System.out.println("Cust data inserted ..."); Toast.makeText(PizzaDetailSubActivity.this,"Thank You Visit Again...",Toast.LENGTH_SHORT).show(); } else { System.out.println("Cust data cannot be inserted ..."); } } } public void onClickAddToCart(View view){ reg_address=datalayoutaddress.getText().toString(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Toast.makeText(this,timePicker2.getHour()+":"+timePicker2.getMinute(),Toast.LENGTH_SHORT).show(); time_=timePicker2.getHour()+":"+timePicker2.getMinute(); reg_qty=qty.getText().toString(); System.out.println("Cart Time:"+timePicker2.getHour()+":"+timePicker2.getMinute()); System.out.println("Quantity : "+reg_qty); System.out.println( registeration_name+registeration_username+registeration_password+registeration_phone+pizza_name1+pizza_price+mode_of_trnf+reg_address+time_+reg_qty); } } public void onClickOffers(View view){ } public void onClickBack(View view){ new Intent(this,PizzaDetailss.class); } } package com.example.puja.pizzahut; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; public class InsertDatabaseHandler extends SQLiteOpenHelper{ private final static String TABLE_NAME2="customer"; private final static String DATABASE_NAME = "PIZZA.DB"; private final static String CartCOL1 = "ID"; private final static String CartCol2="NAME"; private final static String CartCol3="USERNAME"; private final static String CartCol4="PASSWORD"; private final static String CartCol5="PHONE"; private final static String CartCol6="PIZZA_NAME"; private final static String CartCol7="PRICE"; private final static String CartCol8="MODE_OF_TRANS"; private final static String CartCol9="ADDRESS"; private final static String CartCol10="TIME"; private final static String CartCol11="QUANTITY"; public InsertDatabaseHandler(Context context) { super(context, DATABASE_NAME, null, 1); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + TABLE_NAME2 + "(ID INTEGER PRIMARY KEY AUTOINCREMENT,NAME TEXT,PHONE INTEGER,PIZZA_NAME TEXT,PRICE INTEGER,MODE_OF_TRANS TEXT,ADDRESS TEXT,TIME TEXT,QUANTITY INTEGER)"); System.out.println("Customer Table Created ..."); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME2); } public boolean insertCustRecord(String name,String phone,String pizza_name ,String price,String mode,String address,String time_,String qty){ System.out.println(name+phone); SQLiteDatabase db = this.getWritableDatabase(); ContentValues contentValues = new ContentValues(); contentValues.put(CartCol2, name); contentValues.put(CartCol5, phone); contentValues.put("PIZZA_NAME", pizza_name); contentValues.put("PRICE", price); contentValues.put("MODE_OF_TRANS", mode); contentValues.put("ADDRESS", address); contentValues.put("TIME", time_); contentValues.put("QUANTITY", qty); long value=db.insert(TABLE_NAME2, null, contentValues); db.close(); if (value == -1) return false; else return true; } public Cursor getCustData() { SQLiteDatabase db = this.getWritableDatabase(); Cursor cursor = db.rawQuery("select * from " + TABLE_NAME2, null); return cursor; } }
Что я уже пробовал:
PizzaDetailSubAvtivity-это мой класс, подключенный к классу базы данных InsertDatabaseHandler
метод onClickBuyNow внутри PizzaDetailSubActivity передает значения методу базы данных insertCustRecord но insertCustRecord возвращает ложное значение хотя все значения не являются нулевыми