Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Android
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Experimentation for Engineers: From A/B testing to Bayesian optimization
this week in the
Design
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Tim Cooke
Paul Clapham
Liutauras Vilda
Sheriffs:
Junilu Lacar
Rob Spoor
Jeanne Boyarsky
Saloon Keepers:
Stephan van Hulst
Carey Brown
Tim Holloway
Piet Souris
Bartenders:
Forum:
Android
why it doesn't create data base table
shawn peter
Ranch Hand
Posts: 1325
1
posted 9 years ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
this is my DB class
package com.connection.phonedetails; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteOpenHelper; import android.widget.Toast; public class DatabaseHandler extends SQLiteOpenHelper { // All Static variables // Database Version private static final int DATABASE_VERSION = 1; // Database Name private static final String DATABASE_NAME = "simManager"; // sim table name private static final String TABLE_SIM = "simnumbers"; // sim Table Columns names //private static final String KEY_ID = "id"; private static final String KEY_NAME = "name"; private static final String KEY_SIM_NO = "sim_number"; private static final String KEY_SIM_TYPE = "sim_type"; private static String global=""; public DatabaseHandler(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } // Creating Tables @Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub //db.execSQL("DROP TABLE IF EXISTS " + TABLE_SIM); String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_SIM + "(" + KEY_NAME + " TEXT," + KEY_SIM_NO + " TEXT PRIMARY KEY" + KEY_SIM_TYPE + " TEXT" + ")"; db.execSQL(CREATE_CONTACTS_TABLE); global="TRUE"; } // Upgrading database @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // Drop older table if existed //db.execSQL("DROP TABLE IF EXISTS " + TABLE_SIM); // Create tables again onCreate(db); } public void addContact(SimDetails contact) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_NAME, contact.get_name()); // Contact Name values.put(KEY_SIM_NO, contact.get_serial_number()); // Contact sim serial Number values.put(KEY_SIM_TYPE, contact.get_sim_type()); // Inserting Row db.insert(TABLE_SIM, null, values); db.close(); // Closing database connection } // Getting single contact public SimDetails getContact(String id) { SimDetails product = new SimDetails(); try{ //SimDetails product = new SimDetails(); String query = "Select * FROM " + TABLE_SIM+ " WHERE " + KEY_SIM_NO + " = \"" + id + "\""; SQLiteDatabase db = this.getReadableDatabase(); //db.execSQL("DROP TABLE IF EXISTS " + TABLE_SIM); Cursor cursor = db.rawQuery(query, null); if (cursor.moveToFirst()) { cursor.moveToFirst(); product.set_name((cursor.getString(0))); product.set_serial_number((cursor.getString(1))); product.set_sim_type((cursor.getString(2))); cursor.close(); } else { //product.set_name(global); } }catch(Exception e){ product.set_name(global); e.printStackTrace(); } return product; } // Deleting single contact public void deleteContact(SimDetails contact) { String query = "Select * FROM " + TABLE_SIM + " WHERE " + KEY_SIM_NO + " = \"" + contact.get_serial_number() + "\""; SQLiteDatabase db = this.getWritableDatabase(); db.execSQL(query); db.close(); //Cursor cursor = db.rawQuery(query, null); /*SimDetails product = new SimDetails(); if (cursor.moveToFirst()) { //product.setID(Integer.parseInt(cursor.getString(0))); db.delete(TABLE_SIM, KEY_SIM_NO + " = ?", new String[] { String.valueOf(product.) }); db.close(); cursor.close(); } return result;*/ } }
this is my main class
package com.connection.phonedetails; import com.connection.phonedetails.R; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.telephony.TelephonyManager; import android.widget.Toast; public class AndroidSQLiteTutorialActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try{ setContentView(R.layout.main); TelephonyManager telephonyManager = ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE)); DatabaseHandler db = new DatabaseHandler(this); db.addContact(new SimDetails( telephonyManager.getSimSerialNumber(), telephonyManager.getNetworkOperatorName(),"Post")); SimDetails data=db.getContact(telephonyManager.getSimSerialNumber()); if(data != null){ //db.deleteContact(data); Toast.makeText(getApplicationContext(), "DATA is nulll",Toast.LENGTH_LONG).show(); }else{ Toast.makeText(getApplicationContext(), "NOOOOOOOOOOO",Toast.LENGTH_LONG).show(); } }catch(Exception e){ e.printStackTrace(); } } }
but value for data is null.
I am getting below error
06-16 23:30:11.274: W/System.err(415): android.database.sqlite.SQLiteException: no such table: simnumbers: , while compiling: Select * FROM simnumbers WHERE sim_number = "8994029702838521395" 06-16 23:30:11.274: W/System.err(415): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method) 06-16 23:30:11.274: W/System.err(415): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92) 06-16 23:30:11.274: W/System.err(415): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65) 06-16 23:30:11.274: W/System.err(415): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83) 06-16 23:30:11.284: W/System.err(415): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49) 06-16 23:30:11.284: W/System.err(415): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42) 06-16 23:30:11.284: W/System.err(415): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1364) 06-16 23:30:11.284: W/System.err(415): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1332) 06-16 23:30:11.284: W/System.err(415): at com.connection.phonedetails.DatabaseHandler.getContact(DatabaseHandler.java:90) 06-16 23:30:11.284: W/System.err(415): at com.connection.phonedetails.AndroidSQLiteTutorialActivity.onCreate(AndroidSQLiteTutorialActivity.java:23) 06-16 23:30:11.294: W/System.err(415): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 06-16 23:30:11.294: W/System.err(415): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623) 06-16 23:30:11.294: W/System.err(415): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675) 06-16 23:30:11.294: W/System.err(415): at android.app.ActivityThread.access$1500(ActivityThread.java:121) 06-16 23:30:11.294: W/System.err(415): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943) 06-16 23:30:11.294: W/System.err(415): at android.os.Handler.dispatchMessage(Handler.java:99) 06-16 23:30:11.294: W/System.err(415): at android.os.Looper.loop(Looper.java:130) 06-16 23:30:11.294: W/System.err(415): at android.app.ActivityThread.main(ActivityThread.java:3701) 06-16 23:30:11.294: W/System.err(415): at java.lang.reflect.Method.invokeNative(Native Method) 06-16 23:30:11.294: W/System.err(415): at java.lang.reflect.Method.invoke(Method.java:507) 06-16 23:30:11.294: W/System.err(415): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 06-16 23:30:11.294: W/System.err(415): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624) 06-16 23:30:11.304: W/System.err(415): at dalvik.system.NativeStart.main(Native Method)
i don't know why it doesn't create the talbe.please help.
Ameet Sagar
Greenhorn
Posts: 7
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
the problem is with your table creation query.
it is
String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_SIM + "(" + KEY_NAME + " TEXT," + KEY_SIM_NO + " TEXT PRIMARY KEY" + KEY_SIM_TYPE + " TEXT" + ")"; db.execSQL(CREATE_CONTACTS_TABLE);
which should be
String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_SIM + "( " + KEY_NAME + " TEXT, " + KEY_SIM_NO + " TEXT PRIMARY KEY, " + KEY_SIM_TYPE + " TEXT " + " )"; db.execSQL(CREATE_CONTACTS_TABLE);
make the missing comma(,) after the primary key clause.
shawn peter
Ranch Hand
Posts: 1325
1
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
thanks
Of course, I found a very beautiful couch. Definitely. And this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
put in LIST Sample Data to debug, also how view SQLITE DB Data from Eclipse IDE for debug purposes
Help to insert/retreive image from database
I have problems: below are correct[DataManipulator.java]
Problem developing app
Not able to Insert data in SQLite
More...