0

I developed a database app in my eclipse using sqlite...i need to send that code to the server whose IP address is given...can help me with the code to be added to my present code...given the code below

public class DatabaseHelper extends SQLiteOpenHelper{
public static final String DATA_BASE="Mydatabase.db";
public static final String TABLE_NAME="Student";
public static final int DATABASE_VERSION=1;
public DatabaseHelper(Context context) {
    super(context, DATA_BASE, null, DATABASE_VERSION);
    // TODO Auto-generated constructor stub
}

@Override
public void onCreate(SQLiteDatabase db) {
    // TODO Auto-generated method stub
    db.execSQL("CREATE TABLE "+TABLE_NAME+"(NAME TEXT,AGE NUMERIC,ADDRESS TEXT)");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub

}

}

the above is the database helper code

below is the main activity code

public class DbExampleActivity extends Activity implements OnClickListener{
Button submit,select;
AlertDialog di;
private SQLiteDatabase sqLiteDatabase;
private SQLiteStatement sqLiteStatement;
private String name,age,address;
private static final String TABLE_NAME="Student";
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    submit=(Button)findViewById(R.id.savebutton);
    select=(Button)findViewById(R.id.detailsbutton);

    DatabaseHelper db=new DatabaseHelper(this);
    sqLiteDatabase=db.getWritableDatabase();
    sqLiteStatement=sqLiteDatabase.compileStatement("insert into "+TABLE_NAME+"(name,age,address)values(?,?,?)");
   submit.setOnClickListener(this);
   select.setOnClickListener(this);

}

@Override
public void onClick(View v) {

    switch (v.getId()) {
    case R.id.detailsbutton:
        Intent in=new Intent(getApplicationContext(),DisplayActivity.class);
        startActivity(in);

        break;
    case R.id.savebutton:
        name=((EditText)findViewById(R.id.editText1)).getText().toString().trim();
        age=((EditText)findViewById(R.id.editText2)).getText().toString().trim();
        address=((EditText)findViewById(R.id.editText3)).getText().toString().trim();

        sqLiteStatement.bindString(1, name);
        sqLiteStatement.bindString(2, age);
        sqLiteStatement.bindString(3, address);
        sqLiteStatement.executeInsert();

        Toast.makeText(getApplicationContext(), "Data Saved", Toast.LENGTH_LONG).show();
        break;
    default:
        break;
    }

}

}

below is the display activity code

  public class DisplayActivity extends Activity {

private ArrayList<String> arraylist=new ArrayList<String>();
private SQLiteDatabase MYdatabase;
ListView listView;
Button back;
EditText ed;
String s;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.display);
    listView=(ListView)findViewById(R.id.listView1);
    ed=(EditText)findViewById(R.id.searcheditText1);


    ed=(EditText)findViewById(R.id.searcheditText1);

        ed.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // TODO Auto-generated method stub
                populateListView(s.toString());
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
                // TODO Auto-generated method stub

            }

            @Override
            public void afterTextChanged(Editable s) {
                // TODO Auto-generated method stub

            }
        });


}



protected void populateListView(String s) {
    DatabaseHelper db=new DatabaseHelper(this);
    MYdatabase=db.getWritableDatabase();
    try {   

        Cursor c=MYdatabase.rawQuery("SELECT* FROM Student WHERE NAME='"+s+"'", null);
        if(c!=null)
        {
            if(c.moveToFirst())
            {
                do {
                    String name=c.getString(c.getColumnIndex("NAME"));
                    String age=c.getString(c.getColumnIndex("AGE"));
                    String address=c.getString(c.getColumnIndex("ADDRESS"));
                    arraylist.add("Name :"+name+"\n"+"Age :"+age+"\n"+"Address :"+address+"\n");

                } while (c.moveToNext());
            }
        }

        c.close();
        c.deactivate();


} catch (SQLiteException e) {

    Log.d(getClass().getSimpleName(), "could not create"+"or open the database");

}
finally
{
    if(MYdatabase!=null)
    {
      MYdatabase.close();
    }
}

listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,arraylist));

}



public void Back(View v)
{
    Intent back=new Intent(DisplayActivity.this,DbExampleActivity.class);
    startActivity(back);
}



 }
Pravitha V
  • 3,308
  • 4
  • 33
  • 51
aravind varma
  • 90
  • 5
  • 13
  • 1
    Maybe its just me, but your question is unclear. You want to send your database file(.db)? Or do you want to send the content of your database? If you want to send your .db file you either need to have your database available on external harddrive or have your phone rooted. Otherwise I advise you to look into Android RESTful services. – Joey Roosing Jun 21 '12 at 05:13
  • @:i want to send my .db file...and i have my file in external database i.e i copied it on harddrive...now what to do? – aravind varma Jun 21 '12 at 05:15

1 Answers1

0

I will assume you want to send it over HTTP. You can find an example in a post by Emmanuel here:

Send files over HTTP

It seems to me this is exactly what you need.

Community
  • 1
  • 1
Joey Roosing
  • 2,145
  • 5
  • 25
  • 42
  • ..what if i want to send the data entered in my app by user to the server..by using tomcat apache – aravind varma Jun 21 '12 at 11:21
  • I cant currently give you sample code. However if you google for "android post request" or "android restful" etc, you will find tons of examples. Do you want to use GET request or POST? – Joey Roosing Jun 21 '12 at 12:45