I am new to android and I am developing a user employee attendance android application where I am storing all the data locally in the sdcard. Now, I need to send this data to server. I want to know the way to POST my data to mysql database server. I have created a method to collect data from my locally stored sqlite database.
private JSONArray getResults()
{
private String DB_PATH = Environment.getDataDirectory().getAbsolutePath() + "/data/http://ift.tt/2050QYp";*emphasized text*
// String myPath = DB_PATH + DB_NAME;// Set path to your database
// String myTable = TABLE_NAME;//Set name of your table
SQLiteDatabase myDataBase = SQLiteDatabase.openDatabase(DB_PATH, null, SQLiteDatabase.OPEN_READONLY);
String searchQuery = "SELECT e.fileno,e._id,time(a.time) time,a.date,a._id as muq FROM enroll as e ,attendance as a WHERE e._id=a.fileno";
Cursor cursor = myDataBase.rawQuery(searchQuery, null );
JSONArray resultSet = new JSONArray();
cursor.moveToFirst();
while (cursor.isAfterLast() == false) {
int totalColumn = cursor.getColumnCount();
JSONObject rowObject = new JSONObject();
for( int i=0 ; i< totalColumn ; i++ )
{
if( cursor.getColumnName(i) != null )
{
try
{
if( cursor.getString(i) != null )
{
Log.d("TAG_NAME", cursor.getString(i) );
rowObject.put(cursor.getColumnName(i) , cursor.getString(i) );
}
else
{
rowObject.put( cursor.getColumnName(i) , "" );
}
}
catch( Exception e )
{
Log.d("TAG_NAME", e.getMessage() );
}
}
}
resultSet.put(rowObject);
cursor.moveToNext();
}
cursor.close();
Log.d("TAG_NAME", resultSet.toString() );
return resultSet;
}
Aucun commentaire:
Enregistrer un commentaire