942,956 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1501
  • Java RSS
Feb 8th, 2010
0

i am unable to create second table in android

Expand Post »
this is helper class .
i m unable create a second table in my sqlite
please observe the following code

Java Syntax (Toggle Plain Text)
  1. helper class.java
  2.  
  3. public class DBAdapter {
  4.  
  5. private static final String DATABASE_NAME="satya_db";
  6. private static final int DATABASE_VERSION=1;
  7. private static Context context;
  8. private SQLiteDatabase db=null;
  9.  
  10. private static String CREATE_TABLE="create table states(_id integer primary key autoincrement,sna varchar(13) not null)";
  11. private static String CREATE_TABLE_P="create table places(_id integer primary key autoincrement,pna varchar(13) not null)";
  12. public DBAdapter(Context ctx)
  13. {
  14. context=ctx;
  15.  
  16. }
  17.  
  18. private static class DatabaseHelper extends SQLiteOpenHelper {
  19.  
  20. DatabaseHelper(Context ctx) {
  21. super(ctx, DATABASE_NAME, null, DATABASE_VERSION);
  22.  
  23. }
  24.  
  25. @Override
  26. public void onCreate(SQLiteDatabase db) {
  27. db.execSQL(CREATE_TABLE );
  28. db.execSQL(CREATE_TABLE_P);
  29. }
  30.  
  31. @Override
  32. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  33. // TODO Auto-generated method stub
  34.  
  35. }
  36. }
  37.  
  38.  
  39. public DBAdapter open()
  40. {
  41. DatabaseHelper dbhelper=new DatabaseHelper(context);
  42. db=dbhelper.getWritableDatabase();
  43. return this;
  44. }
  45.  
  46. public void close()
  47. {
  48. db.close();
  49. }
  50.  
  51. public long insertRow(String sna)
  52. {
  53. ContentValues cv=new ContentValues();
  54. cv.put("sna", sna);
  55.  
  56. return db.insert("states",null,cv);
  57. }
  58. public long insertRowP(String pna)
  59. {
  60. ContentValues cv=new ContentValues();
  61. cv.put("pna", pna);
  62.  
  63. return db.insert("places",null,cv);
  64. }
  65. public int updateRow(ContentValues cvs,String p[])
  66. {
  67. return db.update("states", cvs,"_id=?",p);
  68. }
  69.  
  70. public Cursor equery()
  71. {
  72. return db.rawQuery("select * from states where _id<200",null);
  73. }
  74. }
main class java


Java Syntax (Toggle Plain Text)
  1. package touchmeme.Datalist;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5.  
  6. public class Datalist extends Activity {
  7. /** Called when the activity is first created. */
  8. @Override
  9. public void onCreate(Bundle savedInstanceState) {
  10. super.onCreate(savedInstanceState);
  11. @SuppressWarnings("unused")
  12. DBAdapter db= new DBAdapter();
  13.  
  14.  
  15. }
  16. }
please help me
thanks
Last edited by peter_budo; Feb 8th, 2010 at 8:54 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
satyambnl is offline Offline
1 posts
since Feb 2010
Feb 8th, 2010
0
Re: i am unable to create second table in android
Why you not catching SQLException? There is possibility that execSQL() method is throwing one...
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,649 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: data protection
Next Thread in Java Forum Timeline: interface





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC