Results 1 to 3 of 3
  1. #1
    negar is offline Member
    Join Date
    Apr 2013
    Posts
    16
    Rep Power
    0

    Default execSql can't create a table

    hi all
    i have an app that uses a db to add people
    this is just my first app using sqlite with SqliteOpenHelper and i have searched books and net so much
    but nothing helped....

    the log cat says that my table named "first" has not been created, this is my code:
    Java Code:
    package com.android.App;
    
    
    
    import android.content.ContentValues;
    import android.content.Context;
    import android.database.Cursor;
    import android.database.SQLException;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteOpenHelper;
    import android.util.Log;
    import android.widget.Toast;
    
    public class DBadaptor {
    /*static final String id="ID";
    static final String name="name";*/
    
    //static final String tb_create="create table first(ID integer primary key,name text not null );";
    Context context=null;
     DataBaseHelper DBH;
     SQLiteDatabase db;
    public DBadaptor (Context ct)
    {
    	this.context=ct;
    	DBH=new DataBaseHelper(context);
    }
     private  static class DataBaseHelper extends SQLiteOpenHelper{
    
    	public DataBaseHelper(Context context) {
    		super(context, "Mydb", null,2);
    		
    	}
    
    	@Override
    	public void onCreate(SQLiteDatabase db) {
    		try{
    		db=getWritableDatabase();
    		db.execSQL("CREATE TABLE  first (_id INTEGER PRIMARY KEY ,name TEXT NOT NULL ) ;",null);
    		}
    		catch(Exception e){
    			e.printStackTrace();
    		}
    			
    		
    		
    	}
    
    	@Override
    	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    		// TODO Auto-generated method stub
    
    		db=getWritableDatabase();
    		db.execSQL("DROP TABLE IF EXISTS first;");
    		onCreate(db);
    		
    	}
     }
    	
    	public DBadaptor open() throws SQLException{
    		db=DBH.getWritableDatabase();
    		
    		return this;
    	}
    	 
    
    public void close(){
    	DBH.close();
    }
    public void insert(String id1,String name1){
    	int i=Integer.valueOf(id1);
    	ContentValues cv=new ContentValues();
    	cv.put("_id",i);
    	cv.put("name",name1);
    	db.insert("first",null, cv);
    	Toast.makeText(context,"You have been added",Toast.LENGTH_LONG).show();
    }
    public Cursor getAll(){
    	return db.query("first",new String [] {"_id","name"},null,null,null,null,null);
    	//Cursor c=db.rawQuery("SELECT * FROM first", null);
    	//c.moveToFirst();
    	//return c;
    }
    }

    please help me.....
    This is so important for me to know .......

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: execSql can't create a table

    Do you have the required permissions in your manifest? I don't know what permissions you need for this. I just know that apps without the necessary permissions tend to fail silently or at least mysteriously.
    Get in the habit of using standard Java naming conventions!

  3. #3
    negar is offline Member
    Join Date
    Apr 2013
    Posts
    16
    Rep Power
    0

    Default Re: execSql can't create a table

    dear kjkrum
    there is no need to specific permission for my app
    and as i make all the lines below the "setContentView"(lines using DB) commented, Activitie's design is shown And no error with manifest & permissions ...

Similar Threads

  1. how to create table for each user
    By abhi7080 in forum New To Java
    Replies: 3
    Last Post: 01-04-2012, 07:42 AM
  2. Create Table to Add Total
    By savio21 in forum New To Java
    Replies: 2
    Last Post: 11-30-2011, 03:58 PM
  3. How to Create TabListener for SWT Table
    By Palani in forum SWT / JFace
    Replies: 0
    Last Post: 12-07-2009, 08:31 AM
  4. how to create a table using gui
    By dandon_1912 in forum SWT / JFace
    Replies: 1
    Last Post: 02-27-2009, 01:21 PM
  5. How to create Table programatically in JSF.
    By JavaEmpires in forum JavaServer Faces (JSF)
    Replies: 2
    Last Post: 06-25-2008, 11:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •