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 6141823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:18:08+00:00 2026-05-23T18:18:08+00:00

Pretend I have a table with 2 columns. _id and name. _id is the

  • 0

Pretend I have a table with 2 columns. _id and name. _id is the primary key and I do not want to set this value manually. I want to perform an insert of name=”john,” and let the program create my own _id. I am unclear what “index” to use when inserting and how many question marks to use. Does this code do the job? Should the index for john be 1 or 2?

String TABLENAME = "table";

SQLiteStatement statement = db.compileStatement("INSERT INTO "+TABLENAME+" VALUES(?);");    

statement.bindString(1,"john");

statement.executeInsert();

Next, say I want to manually set my own _id value. Would I change the code to:

String TABLENAME = "table";

SQLiteStatement statement = db.compileStatement("INSERT INTO "+TABLENAME+" VALUES(?,?);");  

statement.bindLong(1,666);  //Manual _id.

statement.bindString(2,"john");

statement.executeInsert();
  • 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-05-23T18:18:09+00:00Added an answer on May 23, 2026 at 6:18 pm

    Your first example where you provide only the name will not work:

    sqlite> create table test (i integer primary key autoincrement, j text);
    sqlite> insert into test values ('asd');
    Error: table test has 2 columns but 1 values were supplied
    sqlite> insert into test values (null, 'asd');
    sqlite> select * from test;
    1|asd
    sqlite> insert into test (j) values ('asd');
    sqlite> select * from test;
    1|asd
    2|asd
    

    so you need to identify the name column as the destination of the sole value this way, (or as you mentioned in your comment pass null):

    SQLiteStatement statement = db.compileStatement("INSERT INTO "+TABLENAME+" (name) VALUES(?);"); 
    

    Your second example should work fine.

    This would apply to some table created this way:

    create table SomeTable (_id integer primary key autoincrement, name text)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's pretend I have a large recipe-database. A table for recipes each with an
Let's pretend I have the following xaml... <UserControl.Resources> <local:ViewModel x:Name=viewModel /> <local:LoadChildrenValueConverter x:Name=valueConverter />
I have two tables. One contains a list of products with the primary key
Let's pretend I have some items in Stuff table. The names are: RedBaloon, SmallBall,
I have a hierarchical set-up going on a table using the whole START WITH
So I have this website that has a search feature which searches a table
Let's pretend I have a project directory that isn't a git repository. This project
Suppose that I have a table my_table(id, x, y) . I want to write
Let's pretend that there's a tags table with a unique field called name .
i have a form, which you can pretend is laid out like Windows Explorer:

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.