sqlite exception handling in Android -


i working on application stores data in sqlite, while creating table android throws exception:

failure 1 : syntax error near table1. on ox12d510 

i unable identify doing wrong. source code:

import android.content.context; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteopenhelper; public class mysqlitehelper extends sqliteopenhelper { public static final string database_name = "bedekar12.db"; public static final int database_version = 1; public static final string column_id = "_id"; public static final string column_1 = "column1"; public static final string product_name = "product_name"; public static final string product_category = "product_category"; public static final string order_id = "order_id"; public static final string order_date = "order_date"; public static final string customer_id = "customer_id"; public static final string total = "total"; public static final string salesman_id = "salesman_id"; public static final string order_status = "order_status"; public static final string product_id = "product_id"; public static final string package_id = "package_id"; public static final string quantity = "quantity"; public static final string packgage = "package"; public static final string weight = "weight"; public static final string price = "price"; public static final string customer_no = "customer_no"; public static final string customer_name = "customer_name"; public static final string customer_add = "customer_add"; public static final string customer_city = "customer_city"; public static final string customer_region = "customer_region"; public static final string customer_postal = "customer_postal"; public static final string contact = "contact"; public static final string customer_title = "customer_title"; public static final string customer_phone = "customer_phone"; public static final string customer_email = "customer_email"; public static final string lat = "lat"; public static final string lng = "lng"; public static final string events_date = "events_date"; public static final string events_msg = "events_msg"; // 1. news table public static final string news_table = "news_table"; public static final string news_create = "create table " + news_table + " ( " + column_id + " integer primary key , " + column_1 + " text not null ); "; // 2. product table public static final string product_table = "product_table"; public static final string product_create = "create table " + product_table + " ( " + column_id + " integer primary key , " + product_id + " text not null, " + product_name + " text not null, " + product_category + " text not null ); "; // 3. order table public static final string order_table = "order_table"; public static final string order_create = "create table " + order_table + " ( " + column_id + " integer primary key, " + order_id + " text not null, " + order_date + " text not null, " + customer_id + " text not null, " + total + " text not null, " + salesman_id + " text not null, " + order_status + " text not null ); "; // 4. return order table public static final string return_order_table = "return_order_table"; public static final string return_order_create = "create table " + order_table + " ( " + column_id + " integer primary key, " + order_id + " text not null, " + order_date + " text not null, " + customer_id + " text not null, " + total + " text not null, " + salesman_id + " text not null, " + order_status + " text not null ); "; // 5. orderdetails table public static final string order_details_table = "details_table"; public static final string order_details_create = "create table " + order_details_table + " ( " + column_id + " integer primary key , " + order_id + " text not null, " + product_id + " text not null, " + package_id + " text not null, " + quantity + " text not null, " + price + " text );"; // 6. return orderdetails table public static final string return_order_details_table = "return_details_table"; public static final string return_order_details_create = "create table " + order_details_table + " ( " + column_id + " integer primary key, " + order_id + " text not null, " + product_id + " text not null, " + package_id + " text not null, " + quantity + " text not null, " + price + " text );"; // 7. package table public static final string packaging_table = "packaging_table"; public static final string packaging_create = "create table " + packaging_table + " ( " + column_id + " integer primary key, " + product_id + " text not null, " + package_id + " text not null, " + packgage + " text not null, " + weight + " text not null, " + quantity + " text not null, " + price + " text not null );"; // 8. customer table public static final string customer_table = "customer_table"; public static final string customer_create = "create table " + customer_table + " ( " + column_id + " integer primary key, " + customer_name + " text not null, " + customer_add + " text not null, " + customer_city + " text not null, " + customer_region + " text not null, " + customer_postal + " text not null, " + contact + " text not null, " + customer_title + " text not null, " + customer_phone + " text not null, " + customer_email + " text not null, " + lat + " text not null, " + lng + " text not null ); "; // 9. event table; public static final string events_table = "events_table"; public static final string events_create = "create table " + events_table + " ( " + column_id + " integer primary key, " + events_date + " text not null, " + events_msg + " text not null ); "; public mysqlitehelper(context context) { super(context, database_name, null, database_version); // todo auto-generated constructor stub } @override public void oncreate(sqlitedatabase db) { db.execsql(news_table); db.execsql(product_table); db.execsql(order_table); db.execsql(return_order_table); db.execsql(order_details_table); db.execsql(return_order_details_table); db.execsql(packaging_table); db.execsql(customer_table); db.execsql(events_table); } @override public void onupgrade(sqlitedatabase db, int version1, int version2) { db.execsql("drop table if exists " + news_table); db.execsql("drop table if exists " + product_table); db.execsql("drop table if exists " + order_table); db.execsql("drop table if exists " + return_order_table); db.execsql("drop table if exists " + order_details_table); db.execsql("drop table if exists " + return_order_details_table); db.execsql("drop table if exists " + packaging_table); db.execsql("drop table if exists " + customer_table); db.execsql("drop table if exists " + events_table); oncreate (db); } } 

you using wrong string in oncreate method... giving table name only, not string create tables.

change this:

@override public void oncreate(sqlitedatabase db) { db.execsql(news_table); db.execsql(product_table); db.execsql(order_table); db.execsql(return_order_table); db.execsql(order_details_table); db.execsql(return_order_details_table); db.execsql(packaging_table); db.execsql(customer_table); db.execsql(events_table); } 

to this:

@override public void oncreate(sqlitedatabase db) { db.execsql(news_create); db.execsql(product_create); db.execsql(order_create); db.execsql(return_order_create); db.execsql(order_details_create); db.execsql(return_order_details_create); db.execsql(packaging_create); db.execsql(customer_create); db.execsql(events_create); } 

as side note, of primary keys should called _id facilitate use android widgets. expect name of primary key (it coded widgets can identify data comes record when things lists).

one last pointer, easier use autoincrement feature ids don't have manage primary keys manually.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -