Reputation: 280
I have make an android app in which i have made an registration activity. After submitting data through application. My database hasn't create please help me.
in other words
I simply make an app in which i have add registration activity and attach local database to create an user table. But i am not able to do this. check out my code
Here is my code ....
package com.thechamp.resgimyapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText name, email, phone, add, password;
Button sign;
SQLiteDatabase sqLiteDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sqLiteDatabase = openOrCreateDatabase("userdata", MODE_PRIVATE, null);
sqLiteDatabase.execSQL("create table if not exists sign(name varchar, email varchar, password varchar, address varchar, phone varchar)");
name = findViewById(R.id.name);
email = findViewById(R.id.email);
phone = findViewById(R.id.phone);
add = findViewById(R.id.add);
password = findViewById(R.id.password);
sign = findViewById(R.id.sign);
sign.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String names = name.getText().toString();
String emails = email.getText().toString();
String passwords = password.getText().toString();
String adds = add.getText().toString();
String phones = phone.getText().toString();
sqLiteDatabase.execSQL("insert into sign values ('"+names+"', '"+emails+"','"+passwords+"', '"+adds+"', '"+phones+"')");
Toast.makeText(getApplicationContext(),"Sucessfully SignUp",Toast.LENGTH_LONG).show();
}
});
}
}
Upvotes: -1
Views: 43
Reputation: 133
I recommend you to use and learn the "room" library, it is easier, faster and more efficient
Upvotes: 1