Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to send database files in android app to server
    primarykey
    data
    text
    <p>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</p> <pre><code>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 } </code></pre> <p>}</p> <p>the above is the database helper code</p> <p>below is the main activity code</p> <pre><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; } } </code></pre> <p>}</p> <p>below is the display activity code</p> <pre><code> public class DisplayActivity extends Activity { private ArrayList&lt;String&gt; arraylist=new ArrayList&lt;String&gt;(); 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&lt;String&gt;(this, android.R.layout.simple_list_item_1,arraylist)); } public void Back(View v) { Intent back=new Intent(DisplayActivity.this,DbExampleActivity.class); startActivity(back); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload