Hi,

Create the table.

Regards

On Sep 20, 1:54 pm, Devendran Raju <[email protected]> wrote:
> On Tue, Sep 20, 2011 at 9:08 AM, Devendran Raju <[email protected]>wrote:
>
>
>
>
>
>
>
>
>
> > ---------- Forwarded message ----------
> > From: Devendran Raju <[email protected]>
> > Date: Mon, Sep 19, 2011 at 7:56 PM
> > Subject: Doubt on database access.
> > To: [email protected]
>
> > This is my code. While run this program i could not access the database.
> > Exception is coming. Please give me the sollution.
>
> > import android.app.Activity;
> > import android.content.Intent;
> > import android.database.Cursor;
> > import android.database.sqlite.SQLiteDatabase;
> > import android.database.sqlite.SQLiteException;
> > import android.os.Bundle;
> > import android.util.Log;
> > import android.view.View;
> > import android.widget.AdapterView;
> > import android.widget.ArrayAdapter;
> > import android.widget.Button;
> > import android.widget.EditText;
> > import android.widget.Spinner;
>
> > public class OwnerRegistration extends Activity implements
> > AdapterView.OnItemSelectedListener {
> >     private final String SAMPLE_DB_NAME = "my_Db";
> >     private final String SAMPLE_TABLE_NAME = "login";
> >     private final String SAMPLE_TABLE_COL = "Questions";
> >     private final String SQ_Table_Name = "tblSecurityQuestion";
> >     int i=0;
> >     String[] ques=new String[10];
>
> >   EditText user_name, password, c_password, F_n, L_n, adr, cty, state, zip,
> > email, security_A;
> > Spinner security_Q;
> > Button button_1, button_2;
> > String user, pass, c_pass, F_name, L_name, Addr, City, State, Zip, Email,
> > Security_A;
> > //String pass;
>
> >    /** Called when the activity is first created. */
> >    @Override
> >    public void onCreate(Bundle savedInstanceState) {
> >        super.onCreate(savedInstanceState);
> >        setContentView(R.layout.registration);
> >        user_name=(EditText)findViewById(R.id.editText1);
> >        password=(EditText)findViewById(R.id.editText2);
> >        c_password=(EditText)findViewById(R.id.editText3);
> >        F_n=(EditText)findViewById(R.id.editText4);
> >        L_n=(EditText)findViewById(R.id.editText5);
> >        adr=(EditText)findViewById(R.id.editText6);
> >        cty=(EditText)findViewById(R.id.editText7);
> >        state=(EditText)findViewById(R.id.editText8);
> >        zip=(EditText)findViewById(R.id.editText9);
> >        email=(EditText)findViewById(R.id.editText10);
> >        security_Q=(Spinner)findViewById(R.id.spinner1);
> >        security_A=(EditText)findViewById(R.id.editText11);
>
> >        Button myButton = (Button) findViewById(R.id.b1);
> >        myButton.setOnClickListener(new View.OnClickListener() {
> >            public void onClick(View v) {
> >                insert();
> >            }
> >        });
> >        Button myButton2 = (Button) findViewById(R.id.b2);
> >        myButton2.setOnClickListener(new View.OnClickListener() {
> >            public void onClick(View v) {
> >                Intent intent = new Intent(getApplicationContext(),
> >                        Session_2Activity.class);
> >                startActivity(intent);
> >            }
> >        });
>
> >        spinnerQry();
>
> >        security_Q.setOnItemSelectedListener(this);
> >        ArrayAdapter<String> adp=new ArrayAdapter<String>(this,
> > android.R.layout.simple_spinner_item, ques);
>
> > adp.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
> >        security_Q.setAdapter(adp);
> >    }
> >        public void onItemSelected(AdapterView<?> parent, View v, int
> > position, long id) {
> >                //tv.setText(items[position]);
> >                }
> >                public void onNothingSelected(AdapterView<?> parent) {
> >                //tv.setText("");
>
> > }
>
> >      public void insert( ) {
> >          user=user_name.getText().toString();
> >          pass=password.getText().toString();
> >          c_pass=c_password.getText().toString();
> >          F_name=F_n.getText().toString();
> >          L_name=L_n.getText().toString();
> >          Addr=adr.getText().toString();
> >          City=cty.getText().toString();
> >          State=state.getText().toString();
> >          Zip=zip.getText().toString();
> >          Email=email.getText().toString();
> >         // Security_Q=security_Q.getText().toString();
> >          Security_A=security_A.getText().toString();
>
> >         Log.v("first",user);
> >         Log.v("last",pass);
>
> >          SQLiteDatabase sampleDB = null;
>
> >          try {
> >                 sampleDB =  this.openOrCreateDatabase(SAMPLE_DB_NAME,
> > MODE_PRIVATE, null);
>
> >                 //sampleDB.execSQL("SELECT "+SAMPLE_TABLE_Spnner+" from
> > "+SQ_Table_Name,new String [] {});
>
> >                 sampleDB.execSQL("INSERT INTO " + SAMPLE_TABLE_NAME
> > +"(user, pwd, c_pwd, f_name, l_name, address, city, state, zip, email,
> > security_a)"+
> >                         " Values
> > ('"+user+"','"+pass+"','"+c_pass+"','"+F_name+"','"+L_name+"','"+Addr+"','" 
> > +City+"','"+State+"','"+Zip+"','"+Email+"','"+Security_A+"');");
>
> >             } catch (SQLiteException se ) {
> >                 Log.e(getClass().getSimpleName(), "Could not create or Open
> > the database");
> >             } finally {
> >                 if (sampleDB != null)
>
> >                     sampleDB.close();
> >                     user_name.setText("");
> >                     password.setText("");
> >                     c_password.setText("");
> >                     F_n.setText("");
> >                     L_n.setText("");
> >                     adr.setText("");
> >                     cty.setText("");
> >                     state.setText("");
> >                     zip.setText("");
> >                     email.setText("");
> >                     //security_Q.setText(spn);
> >                     security_A.setText("");
>
> >             }
> >         }
>
> > private void spinnerQry(){
>
> >            SQLiteDatabase sampleDB = null;
>
> >            try {
> >                sampleDB =  this.openOrCreateDatabase(SAMPLE_DB_NAME,
> > MODE_PRIVATE, null);
>
> >                Cursor c = sampleDB.rawQuery("SELECT "+SAMPLE_TABLE_COL+"
> > FROM " + SQ_Table_Name , null);
>
> >                if (c != null ) {
> >                    if  (c.moveToFirst()) {
>
> >                        for (int i = 0; i < c.getCount(); i++){
> >                            ques[i] =
> > c.getString(c.getColumnIndex(SAMPLE_TABLE_COL));
>
> >                       }
> >                    }
>
> >                }
>
> >            } catch (SQLiteException se ) {
> >                Log.e(getClass().getSimpleName(), "Could not create or Open
> > the database");
> >            } finally {
> >                if (sampleDB != null)
> >                    sampleDB.close();
> >            }
> >       }
> > }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to