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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:04:10+00:00 2026-06-12T08:04:10+00:00

I am getting syntax error when trying to insert data into my database when

  • 0

I am getting syntax error when trying to insert data into my database when it is created.

I am using the following code:

//DatabaseHelper class
private static class DatabaseHelper extends SQLiteOpenHelper {
    DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_INSPECTION_TABLE);
        db.execSQL(CREATE_AREA_TABLE);
        db.execSQL(CREATE_RUN_TABLE);
        db.execSQL(CREATE_LOCATION_TABLE);
        db.execSQL(CREATE_INSPECTORS_TABLE);
        db.execSQL(CREATE_ISSUE_LOCATION_TABLE);
        db.execSQL(CREATE_ISSUE_TYPE_TABLE);
        db.execSQL(CREATE_RACKING_SYSTEM_TABLE);
        db.execSQL(CREATE_COMPONENT_TABLE);
        db.execSQL(CREATE_RISK_TABLE);
        db.execSQL(CREATE_ACTION_TABLE);
        db.execSQL(CREATE_MANUFACTURER_TABLE);

        db.rawQuery("INSERT INTO " + INSPECTORS_TABLE + "(" + INSPECTOR_NAME + ") " + 
                "SELECT 'Joe Bloggs' AS " + INSPECTOR_NAME +
                " UNION SELECT 'John Major' " +
                " UNION SELECT 'Dan the man'"
                , null);

        db.rawQuery("INSERT INTO " + ACTION_TABLE + "(" + ACTION_REQUIRED + ") " + 
                "SELECT 'Red Risk' AS " + ACTION_REQUIRED +
                " UNION SELECT 'Amber Risk' " +
                " UNION SELECT 'Green Risk'"
                , null);

Edited again following RedFliter’s great advice. I’m sure the query is now right, but although I don’t get any errors no records get inputed into the tables (deleted the database each time using the DDMS).

Am I putting this code in the right place (i.e. onCreate)?

Not sure where I’m going wrong..

Many thanks.

  • 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-12T08:04:11+00:00Added an answer on June 12, 2026 at 8:04 am

    You need to add single quotes around your strings:

    db.rawQuery("INSERT INTO " + INSPECTIONS_TABLE + " (" + INSPECTOR_NAME + ")          VALUES " + "('Joe Blogs', 'John Smith', 'Franky Hollywood')", null); 
    

    This approach is subject to SQL injections. You will need to guard against this.

    Update:

    For multiple row inserts, you need to do:

    db.rawQuery("INSERT INTO " + INSPECTIONS_TABLE + "(" + INSPECTOR_NAME + ") " + "select 'Joe Bloggs' as " + INSPECTOR_NAME + " UNION ALL select 'John Major' UNION ALL select 'Dan the man'", null); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When trying to INSERT data into a database table, I've been getting the following
I am trying to insert a data into SQLite database using Python. INSERT INTO
I am trying to insert data into a PostgreSQL database table using Python. I
I am trying to insert serialize values into ac_services table but getting error: syntax
Hi I am trying insert data into the database using prepared statement but I
while trying to insert data i am getting this error 07-29 18:15:19.909: E/sqlite(863): android.database.sqlite.SQLiteException:
Ok, when trying to insert into the database I'm getting this error You have
I'm trying to do: raw_input(Anyone Home?) But I'm getting syntax error! I'm using Python
I'm trying to execute the following code, but I'm getting SyntaxError: invalid syntax at
I am getting syntax error with the following statement REPLACE INTO users (screenname, token,

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.