mardi 10 février 2015

how to retrieve password value from the database

In this userdetails.java i am creating creating a table by name userdetails and inserting values



public class userdetails extends Activity implements OnClickListener {

@Override

public void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
setContentView(R.layout.activity_userdetails);

Button dbsave = (Button)findViewById(R.id.save);
dbsave.setOnClickListener(this);

SQLiteDatabase db;
db = openOrCreateDatabase( "Student.db" , SQLiteDatabase.CREATE_IF_NECESSARY , null );
try {
final String UserDetails = "CREATE TABLE IF NOT EXISTS UserDetails ("
+ "NAME,"
+ "MOB_NO,"
+ "Q_NO,"
+ "Q_ANS,"
+ "MAIL_ID,"
+ "PASSWD);";
db.execSQL(UserDetails);

Toast.makeText(userdetails.this, "table created ", Toast.LENGTH_LONG).show();



}
catch (Exception e) {
Toast.makeText(userdetails.this, "ERROR "+e.toString(), Toast.LENGTH_LONG).show();
}
}
public void onClick(View view){

SQLiteDatabase db;

if(view.getId()==R.id.save)
{

EditText e1 = (EditText) findViewById(R.id.editText1);
String s1=e1.getText().toString();

EditText e2 = (EditText) findViewById(R.id.editText2);


EditText e3 = (EditText) findViewById(R.id.editText3);
String s3=e3.getText().toString();


EditText e4 = (EditText) findViewById(R.id.editText4);
String s4=e4.getText().toString();


EditText e5 = (EditText) findViewById(R.id.editText5);
String s5=e5.getText().toString();


EditText e6 = (EditText) findViewById(R.id.editText6);
String s6 =e6.getText().toString();

// Toast.makeText(Databasedb.this, "table created ", Toast.LENGTH_LONG).show();

String sql =
"INSERT or replace INTO UserDetails (" +
"Name, " +
"Mob_no, " +
"Q_no, " +
"Q_ans,"+
"Mail_id,"+
"Passwd) " +
"VALUES('"+s1+"','"+e2+"','"+s6+"','"+s3+"','"+s4+"','"+s5+"')" ;

db = openOrCreateDatabase( "Student.db" , SQLiteDatabase.CREATE_IF_NECESSARY , null );

db.execSQL(sql);




AlertDialog alertDialog = new AlertDialog.Builder(userdetails.this).create();
// alertDialog.setTitle("Alert Dialog");

alertDialog.setMessage("uservalues are successfully added/updated to the database");

alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {

Intent intent = new Intent(userdetails.this, Login.class);
userdetails.this.startActivity(intent);

}
});
alertDialog.show();
}}


}


and here is my login.java file from where i need to access the userdetails table



public class Login extends Activity implements OnClickListener {


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);

Button login = (Button) findViewById(R.id.login);
login.setOnClickListener(this);

Button exit = (Button) findViewById(R.id.exit);
exit.setOnClickListener(this);

TextView txt = (TextView) findViewById(R.id.sub);
txt.setOnClickListener(this);

TextView forgot = (TextView) findViewById(R.id.code);
forgot.setOnClickListener(this);

}

@Override

public void onClick(View view) {

if(view.getId() == R.id.login)
{

EditText p1 = (EditText)findViewById(R.id.inputpasswd);
String s = p1.getText().toString();

Intent intent1= new Intent(this,homepage.class);
startActivity(intent1);

}


else
if(view.getId()==R.id.sub)
{
Intent intent2 = new Intent(this, userdetails.class);
startActivity(intent2);
}
else
{
Intent intent3 = new Intent(this, Forgotpassword.class);
startActivity(intent3);

}


}


}


please any one help me to retrieve values(from login.java) from the database`and comapare that value from the user entered value


thanx in advance....


Aucun commentaire:

Enregistrer un commentaire