Note that there are some explanatory texts on larger screens.

plurals
  1. POrawquery select as a database input
    text
    copied!<p>I want to know how to get the value of the selected rawquery</p> <pre><code>Cursor data = dbObject.rawQuery("SELECT _id FROM COMAPNY WHERE _id LIKE ?", new String[] { "%" + val2 + "%" }); </code></pre> <p>as a sqlite database input. i want to select the number (<code>val2</code>) and then put that number to <code>handle.KEY_ID2</code> column. is it possible and how to do it?</p> <p><strong>FULL CODE</strong></p> <p><strong>DataBase</strong></p> <pre><code>package test.com; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteOpenHelper; public class handle extends SQLiteOpenHelper { public static final String DB_NAME = "SHARE_DB"; public static final String DB_COMPANYTABLE = "COMAPNY"; public static final String DB_SHARETABLE = "SHARE"; public static final int DB_VERSION = 1; public static final String KEY_ID = "_id"; public static final String KEY_ID2 = "_id2"; public static final String ROW_ID = "_id"; public static final String COMPANY_NAME = "Name"; public static final String COMPANY_SHAREP = "Price"; public static final String COMPANY_SHAREV = "Volume"; public handle(Context context, String name, CursorFactory factory, int version) { super(context, name, factory, version); // TODO Auto-generated constructor stub } @Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub db.execSQL(SCRIPT_CREATE_DATABASE); db.execSQL(SCRIPT_CREATE_DATABASE2); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub db.execSQL("DROP TABLE IF EXISTS " + DB_COMPANYTABLE); db.execSQL("DROP TABLE IF EXISTS " + DB_SHARETABLE); onCreate(db); } private static final String SCRIPT_CREATE_DATABASE = "create table " + DB_COMPANYTABLE + " (" +KEY_ID + " integer primary key autoincrement, " + COMPANY_NAME + " text not null);"; private static final String SCRIPT_CREATE_DATABASE2 = "create table " + DB_SHARETABLE + " (" + ROW_ID + " integer primary key autoincrement, " + KEY_ID2 + " integer, " + COMPANY_SHAREP + " text not null, " + COMPANY_SHAREV + " text not null);"; } </code></pre> <p><strong>Activity1</strong></p> <pre><code>private ListView.OnItemClickListener listContentOnItemClickListener = new ListView.OnItemClickListener(){ @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { Company comid = new Company(); Cursor cursor = (Cursor) parent.getItemAtPosition(position); int item_id = cursor.getInt(cursor.getColumnIndex(handle.KEY_ID)); String item = String.valueOf(item_id); comid.setCompanyID(item); startActivity(new Intent("android.intent.action.next")); }}; </code></pre> <p><strong>Activity2</strong></p> <pre><code> Company obj1 = new Company(); String val1 = obj1.getCompanyID(); protected void saveRecord() { // TODO Auto-generated method stub conValue.put(handle.COMPANY_SHAREP, two.getText().toString()); conValue.put(handle.COMPANY_SHAREV, three.getText().toString()); conValue.put(handle.KEY_ID2, four.getText().toString()); dbObject.insert(handle.DB_SHARETABLE, null, conValue); } </code></pre> <p>As for now i have to enter the KEY_ID2, but what i want is.. when the user click on the ACTIVITY1 list... it send the row id as "val1" &amp; i want that value to be entered on ACTIVITY2 button click</p>
 

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