I'm new to Android Application Development. I am trying to Insert values in Database. My code is
public void onClick(View view)
{
if(view==register)
{
if(user_id.getText().toString().trim().length()==0||
password.getText().toString().trim().length()==0||
email.getText().toString().trim().length()==0 || contact.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter all values");
return;
}
db.execSQL("INSERT INTO customer VALUES('"+user_id.getText()+"','"+password.getText()+
"','"+email.getText()+"','"+contact.getText()+"');");
showMessage("Success", "Record added"); // showMessage is Print function
clearText();
}
}
As i inserted Duplicate user_id my application get closed. I want to display message dat User id is not available on duplicate entries. can i use try catch block ? or something else. Please suggest.
Aucun commentaire:
Enregistrer un commentaire