i'm totally new to android.i have android app with two text fields and one submit button and also i create database in my serverside using phpmyadmin.what i want to do is, when user submit those two values it's should be insert to server side table.
DB name : test | table name : student | table fields : id,uname
-main activity oncreate-
btn = (Button) findViewById(R.id.button1);
mEDitTxt = (EditText) findViewById(R.id.editText1);
mEDitTxt2 = (EditText) findViewById(R.id.EditText02);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String Id=mEDitTxt.getText().toString();
String Unm=mEDitTxt2.getText().toString();
insertconfig(Id, Unm);
}
});
i have this code.but i don't know how to bind those functions and how i connect with webserver and database.i don't know below codes are need for this or not.please help me
-DBAdapter-
public class DBAdapter
{
private static final String DATABASE_CONFIGTABLE = "student";
public static final String KEY_KEY = "id";
public static final String KEY_VALUE= "uname";
SQLiteDatabase mDb;
Context mCtx;
DBHelper mDbHelper;
public DBAdapter(Context context)
{
this.mCtx = context;
}
public DBAdapter open() throws SQLException
{
mDbHelper = new DBHelper(mCtx);
mDb = mDbHelper.getWritableDatabase();
return this;
}
public void close()
{
mDbHelper.close();
}
public long insertconfig(String Id,String Unm)
{
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_KEY, Id);
initialValues.put(KEY_VALUE, Unm);
return mDb.insert(DATABASE_CONFIGTABLE, null, initialValues);
}
}
-DBHelper-
public class DBHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "SAMPLE.db";
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_CONFIGTABLE = "student";
public static final String KEY_KEY = "id";
public static final String KEY_VALUE= "uname";
private static final String DATABASECONFIG_CREATE = "CREATE TABLE "+DATABASE_CONFIGTABLE+" ("+KEY_KEY+" varchar,"+KEY_VALUE+" varchar);";
Context c;
SQLiteDatabase db;
public DBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
c = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASECONFIG_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_CONFIGTABLE);
onCreate(db);
}
}
Aucun commentaire:
Enregistrer un commentaire