i have a problem inserting a row into sqlite database on rawquery of android studio project, that is multiple same rows are inserted at time execution of rawquery() method
`
public class Register1 extends AppCompatActivity {
SQLiteDatabase db=null;
Button register;
EditText name,mobile,email,password,cpassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register1);
db=openOrCreateDatabase("mydb", MODE_PRIVATE, null);
db.execSQL("create table if not exists login(name varchar,mobile_no varchar,email_id varchar,password varchar,flag varchar)");
register=(Button)findViewById(R.id.register1);
name=(EditText)findViewById(R.id.name);
mobile=(EditText)findViewById(R.id.mobile);
email=(EditText)findViewById(R.id.email);
password=(EditText) findViewById(R.id.password);
cpassword=(EditText)findViewById(R.id.cpassword);
db=openOrCreateDatabase("mydb", MODE_PRIVATE, null);
db.execSQL("create table if not exists login(name varchar,mobile_no varchar,email_id varchar,password varchar,flag varchar)");
db.execSQL("insert into login values('name','mobile','password','type')");
}
}
` above code is summarised as the actual code of my project.
To insert a new row into sqlite , you can use an object of ContentValues class . See below the example (Let's consider that name, mobile , password and type are the key attribute and login is the name of the table ):
ContentValues values = new ContentValues();
values.put("name", nameValue);
values.put("mobile", mobileValue);
values.put("password", passwordValue);
values.put("type", typeValue);
long id = db.insert("login", null, values);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.