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

  • Home
  • SEARCH
  • 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 9216479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:25:34+00:00 2026-06-18T02:25:34+00:00

I’m making an SQLiteDatabase based from this source , but I’ve run into a

  • 0

I’m making an SQLiteDatabase based from this source, but I’ve run into a syntax error that I can’t figure out. I’ve seen the other posts on StackOverflow about this, but they don’t seem to help. In those cases, they contain an extra space somewhere, or a reserved word, but I’ve tried different combinations of spacing and made sure none of the words are reserved.

The only thing I can think of is that I’m making two tables in one database, is that unacceptable? Here’s the gist of the code that’s causing the problem:

//table name
private static final String TABLE_INGREDIENTS = "table_ingredients";
private static final String TABLE_UNITS = "table_units";

//column names
private static final String ING_KEY_ID = "ing_id";
private static final String ING_KEY_NAME = "ing_name";
private static final String ING_KEY_DENSITY = "ing_density";    
private static final String UNIT_KEY_ID = "unit_id";
private static final String UNIT_KEY_NAME = "unit_name";
private static final String UNIT_KEY_BASE_VALUE = "unit_base_value";
private static final String UNIT_KEY_FINAL_VALUE = "unit_final_value";
private static final String UNIT_KEY_IS_WEIGHT = "unit_is_weight";

// Create Tables
@Override
public void onCreate(SQLiteDatabase db) 
{
    String CREATE_ING_TABLE = "CREATE INGREDIENTS TABLE IF NOT EXISTS " + TABLE_INGREDIENTS + "("
            + ING_KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + ING_KEY_NAME + " TEXT,"
            + ING_KEY_DENSITY + " REAL" + ")";
    db.execSQL(CREATE_ING_TABLE);

    String CREATE_UNIT_TABLE = "CREATE UNITS TABLE IF NOT EXISTS " + TABLE_UNITS + "("
            + UNIT_KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + UNIT_KEY_NAME + " TEXT,"
            + UNIT_KEY_BASE_VALUE + " REAL," + UNIT_KEY_FINAL_VALUE + " REAL,"
            + UNIT_KEY_IS_WEIGHT + " INTEGER" + ")";        
    db.execSQL(CREATE_UNIT_TABLE);
}

And here’s my log output just in case my interpretation is wrong:

02-01 12:48:43.855: D/QBCPro:::(7186): LoadAllTask doInBackground called...
02-01 12:48:43.855: D/QBCPro:::(7186): Entering onResume()...
02-01 12:48:43.875: E/SQLiteLog(7186): (1) near "INGREDIENTS": syntax error
02-01 12:48:43.875: W/dalvikvm(7186): threadid=11: thread exiting with uncaught exception (group=0x41eb8300)
02-01 12:48:43.895: E/AndroidRuntime(7186): FATAL EXCEPTION: AsyncTask #1
02-01 12:48:43.895: E/AndroidRuntime(7186): java.lang.RuntimeException: An error occured while executing doInBackground()
02-01 12:48:43.895: E/AndroidRuntime(7186):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at java.lang.Thread.run(Thread.java:856)
02-01 12:48:43.895: E/AndroidRuntime(7186): Caused by: android.database.sqlite.SQLiteException: near "INGREDIENTS": syntax error (code 1): , while compiling: CREATE INGREDIENTS TABLE IF NOT EXISTS table_ingredients(ing_id INTEGER PRIMARY KEY AUTOINCREMENT,ing_name TEXT,ing_density REAL)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at com.sfware.quickbakeconverterpro.DatabaseHelper.onCreate(DatabaseHelper.java:49)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at com.sfware.quickbakeconverterpro.DatabaseHelper.open(DatabaseHelper.java:72)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at com.sfware.quickbakeconverterpro.QuickBakeConverterPro$LoadAllTask.doInBackground(QuickBakeConverterPro.java:690)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at com.sfware.quickbakeconverterpro.QuickBakeConverterPro$LoadAllTask.doInBackground(QuickBakeConverterPro.java:1)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
02-01 12:48:43.895: E/AndroidRuntime(7186):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
02-01 12:48:43.895: E/AndroidRuntime(7186):     ... 5 more
02-01 12:48:44.045: D/libEGL(7186): loaded /system/lib/egl/libEGL_mali.so
02-01 12:48:44.135: D/libEGL(7186): loaded /system/lib/egl/libGLESv1_CM_mali.so
02-01 12:48:44.145: D/libEGL(7186): loaded /system/lib/egl/libGLESv2_mali.so
02-01 12:48:44.215: D/OpenGLRenderer(7186): Enabling debug mode 0
02-01 12:48:44.400: D/QBCPro:::(7186): Entering onPause()...
02-01 12:48:44.405: D/QBCPro:::(7186): Leaving onPause()...
02-01 12:48:44.545: D/QBCPro:::(7186): Entering onStop()...
02-01 12:48:44.545: D/QBCPro:::(7186): About to save data in new SaveAllTask
02-01 12:48:44.545: D/QBCPro:::(7186): Leaving onStop()...
02-01 12:48:44.545: D/QBCPro:::(7186): SaveAllTask doInBackground called...
02-01 12:48:44.560: E/SQLiteLog(7186): (1) near "INGREDIENTS": syntax error

Can anyone spot it for me? I’m still rusty with SQLiteDatabase syntax unfortunately.

  • 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-18T02:25:35+00:00Added an answer on June 18, 2026 at 2:25 am

    Quick fix:

    change to

     String CREATE_ING_TABLE = "CREATE TABLE IF NOT EXISTS " + TABLE_INGREDIENTS + "("
                + ING_KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + ING_KEY_NAME + " TEXT,"
                + ING_KEY_DENSITY + " REAL" + ")";
    

    Explanation:

    The execSQL() method requires a SQL string, which has to be constructed in a specific way, following the guidelines. The original question had CREATEINGREDIENTSTABLE IF NOT EXISTS, which is not supported by the execSQL() method. When it’s replaced by CREATE TABLE IF NOT EXISTS, it will work fine.

    For more info, have a look at the SQLiteDatabase page over on developer.android.com, and specifically the two execSQL() methods.

    • 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
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.