Click here to Skip to main content
12,694,842 members (33,180 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: Mobile Android SQLite
public class DBAdapter {
			
	public static final String COLUMN_ID = "ID";
	public static final String COLUMN_NAME = "NAME";
	public static final String COLUMN_SURNAME = "SURNAME";
	public static final String COLUMN_DATE_OF_BIRTH = "DateOfBirth";
	public static final String COLUMN_ADDRESS = "HomeAddress";
	public static final String COLUMN_EMAIL = "EmailNO";
	public static final String COLUMN_PHONE_NUMBER = "PhoneNumber";
	public static final String COLUMN_CITY = "City";
	public static final String COLUMN_PTYE_PAYMENT = "TypePayment";
	public static final String COLUMN_SHIPPING_TYPE = "ShippingType";
	public static final String COLUMN_CARD_NUMBER = "CardNumber";	
	public static final String COLUMN_username = "usernames";
	public static final String COLUMN_Password = "Passwords";	
	
	public static final String TAG = "DBAdapter";
		
    static final String DATABASE_NAME = "SuperComputers.db";
    static final String USERS_TABLE = "DetailsCustomer";
    static final int DATABASE_VERSION = 3;
	
private final Context context;

private DatabaseHelper DBHelper;
private SQLiteDatabase db;


public DBAdapter (Context ctx) 
{
	this.context=ctx;
	DBHelper = new DatabaseHelper(context);
}

private static class DatabaseHelper extends SQLiteOpenHelper

{
	DatabaseHelper(Context context) {
	
	super (context,DATABASE_NAME,null,DATABASE_VERSION);
			
	}
	
@Override
 public void onCreate(SQLiteDatabase db)
{
	try {
		  //db.execSQL(DATABASE_CREATE);		
		 db.execSQL("CREATE TABLE "+ USERS_TABLE + 
				    "("+ COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
				    COLUMN_NAME + " TEXT, " + COLUMN_SURNAME +" TEXT, " +COLUMN_DATE_OF_BIRTH+
				       " TEXT NOT NULL, " + COLUMN_ADDRESS + " TEXT, " + COLUMN_EMAIL +" TEXT, " + 
				       COLUMN_PHONE_NUMBER + " TEXT, "+ COLUMN_CITY + " TEXT, "+ COLUMN_PTYE_PAYMENT + " TEXT, " + COLUMN_CARD_NUMBER + " TEXT,"+ COLUMN_username + "TEXT ," + COLUMN_Password +" TEXT);");
		 
	} 
	   catch (SQLException e) {
		   e.printStackTrace();
		
	   }
	}
@Override
 public void onUpgrade(SQLiteDatabase db, int oldVersion , int newVesion) {

	Log.w(TAG, "Upgrading database from version " + oldVersion + "to"
			+ newVesion + ", which will destroy all old data");
	db.execSQL("DROP TABLE IF EXISTS " + USERS_TABLE);
	onCreate(db);

   } 
 }

//--open the database---

public DBAdapter open() throws SQLException
{
	db = DBHelper.getWritableDatabase();
	return this;
}

//--closes the database--
public void close()
{
	DBHelper.close();
}

public long insertRecord(String NAME, String SURNAME, String DateOfBirth,
         String HomeAddress,String EmailNO,  String PhoneNumber,  String City,
         long l, long m,String CardNumber,String usernames, String Passwords) {
    {
        ContentValues initialValues = new ContentValues();

        initialValues.put(COLUMN_NAME,NAME);
        initialValues.put(COLUMN_SURNAME,SURNAME);
        initialValues.put(COLUMN_DATE_OF_BIRTH,DateOfBirth);
        initialValues.put(COLUMN_ADDRESS,HomeAddress);
        initialValues.put(COLUMN_EMAIL,EmailNO);
        initialValues.put(COLUMN_PHONE_NUMBER,PhoneNumber);
        initialValues.put(COLUMN_CITY,City);
        initialValues.put(COLUMN_PTYE_PAYMENT,l);
        initialValues.put(COLUMN_SHIPPING_TYPE,m);
        initialValues.put(COLUMN_CARD_NUMBER,CardNumber);
        initialValues.put(COLUMN_username,usernames);
        initialValues.put(COLUMN_Password,Passwords);

        return db.insert(USERS_TABLE,null, initialValues);

       }

   }

public long insertRecord(String nAME, String sURNAME, String dateOfBirth,
        String homeAddress, String emailNO, String phoneNumber, String city,
        String string, String string2, String cardNumber, String usernames, String Passwords) {
    return 0;

    }



And here my class......................................................................
  public void buttonRegister(View v)
    {
    	Log.d("test", "adding");
    	
    	//get data from form
    	EditText nametext = (EditText)findViewById(R.id.editTextName);
    	EditText Surnametext = (EditText)findViewById(R.id.editTextSurname);
    	EditText DOBtext = (EditText)findViewById(R.id.editTextDateBirth);
    	EditText Adresstext = (EditText)findViewById(R.id.editTexAddress);
    	EditText EmailNotext = (EditText)findViewById(R.id.editTeEmail);
    	EditText Phonetext = (EditText)findViewById(R.id.editTexPhone);
    	EditText Citytext = (EditText)findViewById(R.id.editTextCITY);
    	Spinner PaymentSpinner = (Spinner)findViewById(R.id.spinnerPayment);
    	Spinner ShippngMethod = (Spinner)findViewById(R.id.spinnerShipping);
    	EditText CardNumbertext = (EditText)findViewById(R.id.editTextCARDNUMBER);
    	EditText usernametext = (EditText)findViewById(R.id.txtusername);
    	EditText pasword1 = (EditText)findViewById(R.id.editTexpassword);
      //  EditText repasword1 = (EditText)findViewById(R.id.editREPASSWORD);
    	
    	db.open();
    	long id = db.insertRecord(nametext.getText().toString(), Surnametext.getText().toString(),
    			                   DOBtext.getText().toString(),Adresstext.getText().toString(),EmailNotext.getText().toString(),
    			                   Phonetext.getText().toString(), Citytext.getText().toString(),
    			                   PaymentSpinner.getSelectedItemId(), ShippngMethod.getSelectedItemId(), CardNumbertext.getText().toString(),
    			                   usernametext.getText().toString(), pasword1.getText().toString());
    	
    	db.close();
    	    	
    	nametext.setText("");
    	Surnametext.setText("");
    	DOBtext.setText("");
    	Adresstext.setText("");
    	EmailNotext.setText("");
    	Phonetext.setText("");	   
    	Citytext.setText("");
    	PaymentSpinner.setId(0);
    	ShippngMethod.setId(0);
    	CardNumbertext.setText("");
    	CardNumbertext.setText("");
    	usernametext.setText("");
    	pasword1.setText("");
    	
    	
    	Toast.makeText(Regist.this,"Customer has been Registered",Toast.LENGTH_LONG).show();   	   
    
       }
Posted 23-May-12 23:51pm
zamani2452
Updated 24-May-12 0:26am
v2
Comments
Sandeep Mewara 24-May-12 5:30am
   
Did you Google for same error? It returns few similar faced issue with discussion around. Check them.
zamani2 24-May-12 6:03am
   
I did Sandeep
ryanb31 25-May-12 11:19am
   
That's a lot of code to look through for my puny brain but the error is saying that a certain table does not exist. So, likely it either does not exist or the account does not have permissions to it.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

I think your problem is when you ran your code first time the column was not created in the table.So next time when you added more column to your table db is not created again so is your table. Uninstall your application and then run it again.Database and table will be created again.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 1 Aug 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100