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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:29:45+00:00 2026-05-30T22:29:45+00:00

Hi friends. I’m trying to store some data into a 2-table-database. Here is its

  • 0

Hi friends. I’m trying to store some data into a 2-table-database. Here is its definition:

public class SQLManager  {

public static String KEY_ROWID = "_id";
public static final String KEY_PRODUCT = "product";
public static final String KEY_QUANTITY = "quantity";
public static final String KEY_PRICE = "price";

public static final String KEY_DATA = "user data";

private static final String DATABASE_NAME = "PedidoDc";
private static final String DATABASE_TABLE1 = "PedidoTable";
private static final String DATABASE_TABLE2 = "DatosTable";

private static final int DATABASE_VERSION = 1;

private DbHelper ourHelper;
private final Context ourContext;
private SQLiteDatabase ourDatabase;

private static class DbHelper extends SQLiteOpenHelper{

    public DbHelper(Context context) {
        super(context, DATABASE_NAME, null,  DATABASE_VERSION);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL("CREATE TABLE " + DATABASE_TABLE1 + " (" + 
                KEY_ROWID + " INTEGER PRIMARY KEY, " + 
                KEY_PRODUCT + " TEXT NOT NULL, " +
                KEY_QUANTITY + " TEXT NOT NULL, " +
                KEY_PRICE + " TEXT NOT NULL);"

        );

        db.execSQL("CREATE TABLE " + DATABASE_TABLE2 + " (" + 
                KEY_ROWID + " INTEGER PRIMARY KEY, " + 
                KEY_DATA + " TEXT NOT NULL);"

        );

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE1);
        db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE2);
        onCreate(db);

    }


}

public SQLManager(Context c){

    ourContext = c;

}

public SQLManager open() throws SQLException{

    ourHelper = new DbHelper(ourContext);
    ourDatabase = ourHelper.getWritableDatabase();
    return this;
}

    public void close(){

    ourHelper.close();

}

     public long createEntry(String product, String quantity, String price) {
// TODO Auto-generated method stub
ContentValues cv = new ContentValues();
cv.put(KEY_PRODUCT, product);
cv.put(KEY_QUANTITY, quantity);
cv.put(KEY_PRICE, price);

return ourDatabase.insert(DATABASE_TABLE1, null, cv);
  }

   public long createEntry2(String data) {
// TODO Auto-generated method stub
ContentValues cv = new ContentValues();
cv.put(KEY_DATA, data);
return ourDatabase.insert(DATABASE_TABLE2, null, cv);
   }



    public String getData() {
// TODO Auto-generated method stub
String[] columns = new String[]{ KEY_ROWID, KEY_PRODUCT, KEY_QUANTITY, KEY_PRICE};
Cursor c = ourDatabase.query(DATABASE_TABLE1, columns, null, null, null, null, null);
String result = "";

int iRow =  c.getColumnIndex(KEY_ROWID);
int iProduct =  c.getColumnIndex(KEY_PRODUCT);
int iQuantity =  c.getColumnIndex(KEY_QUANTITY);
int iPrice =  c.getColumnIndex(KEY_PRICE);

for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
    result = result  + " " + c.getString(iQuantity) + "    " + c.getString(iProduct) + "                        " + c.getString(iPrice) + "\n";
}

return result;
    }

    public String getUserData() {
// TODO Auto-generated method stub
String[] columns = new String[]{ KEY_ROWID, KEY_DATA};
Cursor c = ourDatabase.query(DATABASE_TABLE2, columns, null, null, null, null, null);
String result = "";

int iRow =  c.getColumnIndex(KEY_ROWID);
int iData =  c.getColumnIndex(KEY_DATA);

for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
    result = result  + " " + c.getString(iData) + "\n";
}

return result;
    }
    public void deleteEntry(long l) {
// TODO Auto-generated method stub

ourDatabase.delete(DATABASE_TABLE1, null, null);


    }

     public String getQuantity(long l) {
// TODO Auto-generated method stub
String[] columns = new String[]{KEY_ROWID, KEY_QUANTITY, KEY_PRODUCT ,KEY_PRICE};
Cursor c = ourDatabase.query(DATABASE_TABLE1, columns, KEY_ROWID + "=" + l, null, null, null, null);
if (c != null){
    c.moveToFirst();
    String quantity = c.getString(1);
    c.close();
    return quantity;



}
return null;
    }

    public String getProduct(long l) {
// TODO Auto-generated method stub
String[] columns = new String[]{KEY_ROWID, KEY_QUANTITY, KEY_PRODUCT ,KEY_PRICE};
Cursor c = ourDatabase.query(DATABASE_TABLE1, columns, KEY_ROWID + "=" + l, null, null, null, null);
if (c != null){
    c.moveToFirst();
    String product = c.getString(2);
    c.close();
    return product;
}
return null;

    }

    public String getPrice(long l) {
// TODO Auto-generated method stub

String[] columns = new String[]{KEY_ROWID, KEY_QUANTITY, KEY_PRODUCT ,KEY_PRICE};
Cursor c = ourDatabase.query(DATABASE_TABLE1, columns, KEY_ROWID + "=" + l, null, null, null, null);
if (c != null){
    c.moveToFirst();
    String price = c.getString(3);
    c.close();
    return price;
}
return null;
    }


    }

And this is the code i use to store some data to the second table:

            SQLManager entry = new SQLManager(ConfirmaData.this);
            entry.open();
            entry.createEntry2(tlf);
            entry.close();

Where tlf is a string variable.

I get this error:

E/Database(27790): android.database.sqlite.SQLiteException: near “data”: syntax error: , while compiling: INSERT INTO DatosTable(user data) VALUES(?);

Any idea?

Thank you!

  • 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-30T22:29:46+00:00Added an answer on May 30, 2026 at 10:29 pm

    I believe the error is due to column name containing space

    public static final String KEY_DATA = "user data";
    

    Remove space between user and data

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

friends, i have a custom view class public class Zoom extends View { private
Friends, I'm lost here. I have this WCF Rest service returning data in json
Friends I had a datagridview in my windowsdesktop application to insert data into the
Friends its really giving me a great head ache about the problem I am
friends i am trying to work with predesigned visual studio dotNet projects. so i
Friends, If I want to know about the new features of Oracle 11gR2 Database
friends, i am using following onDraw method to display bitmap on screen. @Override public
Friends, I am trying to processing a huge amount of audio files using a
friends. I know, there are many questions here already on these iterators. I've read
friends, here is my layout with image and text. i want to show text

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.