I Want to create a login application..
Now in that application first time when i am login it will check username is empty ..if username is empty it will call databasebuild(),tablebuild(),and then insert into that table value..and username is already exists then it will directly call the next page i.e Galaxy_Main..From that device imei number if imei number is same as first
Now in my program i am create all this but still it has errors..
What I have tried:
public class MainActivity extends AppCompatActivity
{
private static final String TAG = null;
Button login;
DatabaseHandler sqLiteHelper;
SQLiteDatabase sqLiteDatabaseObj;
String imeistr;
private TextInputLayout userview ;
private TextInputLayout passview ;
private String SQLiteDataBaseQueryHolder;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sqLiteHelper = new DatabaseHandler(this);
login = (Button) findViewById(R.id.button1);
userview = (TextInputLayout) findViewById(R.id.Username);
passview = (TextInputLayout) findViewById(R.id.Password);
passview = (TextInputLayout) findViewById(R.id.Password);
login.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Cursor c = sqLiteDatabaseObj.rawQuery( "select * from LOGINUSER", null );
c.moveToNext();
String username = userview.getEditText().getText().toString();
String password = passview.getEditText().getText().toString();
if (username.isEmpty())
{
SQLiteDataBaseBuild();
SQLiteTableBuild();
ContentValues cv = new ContentValues();
cv.put(sqLiteHelper.KEY_User, username);
cv.put(sqLiteHelper.KEY_PASS, password);
try
{
sqLiteDatabaseObj.beginTransaction();
sqLiteDatabaseObj.insert(sqLiteHelper.TABLE_NAME, null, cv);
sqLiteDatabaseObj.setTransactionSuccessful();
sqLiteDatabaseObj.endTransaction();
sqLiteDatabaseObj.close();
}
catch (SQLException e)
{
android.util.Log.e(TAG, e.getMessage());
}
}
Toast.makeText(MainActivity.this, "User Login Successfully", Toast.LENGTH_LONG).show();
Intent intent = new Intent(MainActivity.this, Galaxy_Main.class);
startActivity(intent);
}
}
});
}
public void SQLiteDataBaseBuild()
{
sqLiteDatabaseObj = openOrCreateDatabase(DatabaseHandler.DATABASE_NAME, Context.MODE_PRIVATE, null);
}
public void SQLiteTableBuild()
{
sqLiteDatabaseObj.execSQL("CREATE TABLE IF NOT EXISTS " + DatabaseHandler.TABLE_NAME + "(" + DatabaseHandler.KEY_User + " PRIMARY KEY , " + DatabaseHandler.KEY_PASS + " STRING);");
}
}
package com.example.mytrialapplication;
public class DatabaseHandler extends SQLiteOpenHelper
{
static final String DATABASE_NAME = "Galaxy";
public static final String TABLE_NAME = "LOGINUSER";
public static final String KEY_User = "username";
public static final String KEY_PASS = "password";
public static final String KEY_IMEI_NO = "imei_number";
public DatabaseHandler(Context context)
{
super(context, DATABASE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL(SQL_CREATE_ENTRIES);
}
public static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + TABLE_NAME + " (" +KEY_User+ "STRING , "+
KEY_PASS +" STRING,"+ KEY_IMEI_NO + "STRING"+ " )";
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}