Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7873921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:39:20+00:00 2026-06-03T02:39:20+00:00

i’ve the following code, that selects the value from spinner and should write to

  • 0

i’ve the following code, that selects the value from spinner and should write to new table (tbl_trunk)..i used the following code but didn’t work…

myDB.execSQL("CREATE TABLE " + SAMPLE_TABLE_NAME + " (" + _id
                + " INTEGER PRIMARY KEY AUTOINCREMENT , " + cust_name
                + " TEXT , " + cust_add + " TEXT)");
        myDB.execSQL("insert into tbl_customer(cust_name, cust_add) values ('Fool', 'FF' );");

        Cursor c = myDB.query(SAMPLE_TABLE_NAME, null, null, null, null, null, null);

    char cust_nameColumnIndex = (char) c.getColumnIndexOrThrow("cust_name");
            char cust_addColumnIndex = (char) c.getColumnIndexOrThrow("cust_add");
            adapterForSpinner = new ArrayAdapter<String>(this,
                    android.R.layout.simple_spinner_item);
            adapterForSpinner
                    .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            String selection;
            spinner.setAdapter(adapterForSpinner);
            spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

                @SuppressWarnings("null")
                @Override

            public void onItemSelected(AdapterView<?> parent, View view,
                    int pos, long id) {
                // TODO Auto-generated method stub
                SQLiteDatabase myDB = null;

                Toast.makeText(
                        parent.getContext(),
                        "Customer is "
                                + parent.getItemAtPosition(pos).toString(),
                        Toast.LENGTH_LONG).show();
             String selected = parent.getItemAtPosition(pos).toString();
              myDB.execSQL("CREATE TABLE " + SAMPLE_TABLE_TRUNK + " (" + _id
                        + " INTEGER PRIMARY KEY AUTOINCREMENT , " + cust_name
                        + " TEXT)");

myDB.execSQL("insert into tbl_trunk(cust_name) values (pos);");
insert(selected);

insert method is:

public void insert(String cust_name) {
                String SAMPLE_DB_NAME = "db_sales";

                dbHelper = new DatabaseHelper(getBaseContext());     
                SQLiteDatabase db = dbHelper.getWritableDatabase();     
                ContentValues values = new ContentValues();     
                values.put("cust_name", cust_name);     
                db.insert("SAMPLE_TABLE_TRUNK", null, values);     
                db.close();     
                if (SAMPLE_DB_NAME != null)
                {
                    //  SAMPLE_DB_NAME.close(); 
                }

                } 

how should i add the selected row to new table??
the error log is

05-02 19:27:45.048: E/Database(3668): Error inserting cust_name=Ali - AA
05-02 19:27:45.048: E/Database(3668): android.database.sqlite.SQLiteException: no such table: SAMPLE_TABLE_TRUNK: , while compiling: INSERT INTO SAMPLE_TABLE_TRUNK(cust_name) VALUES(?);
05-02 19:27:45.048: E/Database(3668):   at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
05-02 19:27:45.048: E/Database(3668):   at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
05-02 19:27:45.048: E/Database(3668):   at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
05-02 19:27:45.048: E/Database(3668):   at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
05-02 19:27:45.048: E/Database(3668):   at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:36)
05-02 19:27:45.048: E/Database(3668):   at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1145)
05-02 19:27:45.048: E/Database(3668):   at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1536)
05-02 19:27:45.048: E/Database(3668):   at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1410)
05-02 19:27:45.048: E/Database(3668):   at numair.tab.layout.Customers$1.insert(Customers.java:117)
05-02 19:27:45.048: E/Database(3668):   at numair.tab.layout.Customers$1.onItemSelected(Customers.java:87)
05-02 19:27:45.048: E/Database(3668):   at android.widget.AdapterView.fireOnSelected(AdapterView.java:864)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:39:22+00:00Added an answer on June 3, 2026 at 2:39 am

    You create a separate db class as follows with your own parameters:

      public class DataBaseHelper  extends SQLiteOpenHelper{
    private static final String DB_NAME="SampleMsgDb";
    private static final String TABLE="SampleTABLE";
    private static final int DB_VERSION=1;
    private static final String COLUMN1="received_Time";
    private static final String COLUMN2="col1";
    private static final String COLUMN3="col2";
    private  Context myContext;
    private SQLiteDatabase myDataBase;
    DataBaseHelper dbHelper;
    
    public DataBaseHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
        myContext=context;
    }
    
    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        String sql = "create table " + TABLE + "( "+ COLUMN1 + " integer , " + COLUMN2 + " text not null, "
                + COLUMN3 + " text not null);";
        Log.d("EventsData", "onCreate: " + sql);
        db.execSQL(sql);
    }
    
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        if (oldVersion >= newVersion)
            return;
    
        String sql = null;
        if (oldVersion == 1) 
            sql = "alter table " + TABLE + " add note text;";
        if (oldVersion == 2)
            sql = "";
    
        Log.d("EventsData", "onUpgrade  : " + sql);
        if (sql != null)
            db.execSQL(sql);
    }
    public void insert(String number, String message) {
        dbHelper=new DataBaseHelper(myContext);
            SQLiteDatabase db = dbHelper.getWritableDatabase();
            ContentValues values = new ContentValues();
            values.put(DataBaseHelper.COLUMN1, System.currentTimeMillis());
            values.put(DataBaseHelper.COLUMN2, number);
            values.put(DataBaseHelper.COLUMN3, message);
            db.insert(DataBaseHelper.TABLE, null, values);
            db.close();
            if (myDataBase != null)
                myDataBase.close();
    
          }
    
     @Override
        public synchronized void close() {
          super.close();
            if (myDataBase != null)
                myDataBase.close();
    
        }}
    

    in activity class remove all db related queries and add

    DataBaseHelper dbHelper;  
      this.dbHelper=new DataBaseHelper(YOURACTIVITYCLASS.this);   
      dbHelper.insert("121", "some text111");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.