vendredi 27 février 2015

Need Help for SQLite Database where clause query

Hii I am trying to get a value from listview from one activity and pass that value into where clause in sqlite query in another activity. But when I query gets executed it gives Unfortunately app has stopped working error. Code is as follows:



import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class newclass extends Activity {
private static final Context Context = null;
SQLiteDatabase db1=null;
private static String DBNAME ="PERSONS.db";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newacti);
TextView Textv = (TextView)findViewById(R.id.tv1);
Intent iin= getIntent();
Bundle b = iin.getExtras();
db1 = openOrCreateDatabase(DBNAME,Context.MODE_PRIVATE,null);
if(b!=null)
{
String j =(String) b.get("name");
Textv.setText(j);
//Below 2 lines gives an error "Unfortunately app has stopped working error"
String sqlQuery = "select * from TBUSER where ID='"+ j+"'";
Toast.makeText(Context, sqlQuery, Toast.LENGTH_LONG).show();
/*db1 = openOrCreateDatabase(DBNAME,Context.MODE_PRIVATE,null);
Cursor c= db1.rawQuery(sqlQuery, null);
if (c != null && c.moveToFirst()) {
do {
//do something
} while (c.moveToNext());
}*/

}
}

}


Can anybody say me whats an error. Thank You in Advance.


Aucun commentaire:

Enregistrer un commentaire