Advertisement
Guest User

Untitled

a guest
Sep 1st, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.06 KB | None | 0 0
  1. public class SQLite_helper extends SQLiteOpenHelper {
  2.  
  3. public static final String MYDATABASE_TABLE = "Stripclubs_table_test";
  4. public static final String KEY_ID = "_id";
  5. public static final String KEY_CONTENT1 = "Name";
  6. public static final String KEY_CONTENT2 = "Town";
  7. public static final String KEY_CONTENT3 = "State";
  8. public static final String KEY_CONTENT4 = "Phone";
  9. public static final String KEY_CONTENT5 = "Website";
  10. public static final String KEY_CONTENT6 = "Description";
  11. public static final String KEY_CONTENT7 = "Stars";
  12. public static final String KEY_CONTENT8 = "Latitude";
  13. public static final String KEY_CONTENT9 = "Longitude";
  14. public static final String KEY_CONTENT10 = "zipcode";
  15. public static final String KEY_CONTENT11 = "id";
  16.  
  17.  
  18.  
  19. private static final String SCRIPT_CREATE_DATABASE =
  20. "create table " + MYDATABASE_TABLE + " ("
  21. + KEY_ID + " integer primary key autoincrement, "
  22. + KEY_CONTENT1 + " text, "
  23. + KEY_CONTENT2 + " text, "
  24. + KEY_CONTENT3 + " text, "
  25. + KEY_CONTENT4 + " text, "
  26. + KEY_CONTENT5 + " text, "
  27. + KEY_CONTENT6 + " text, "
  28. + KEY_CONTENT7 + " text, "
  29. + KEY_CONTENT8 + " text, "
  30. + KEY_CONTENT9 + " text, "
  31. + KEY_CONTENT10 + " text, "
  32. + KEY_CONTENT11 + " text)";
  33.  
  34.  
  35.  
  36. public SQLite_helper(Context context, String name, CursorFactory factory,
  37. int version) {
  38. super(context, name, factory, version);
  39. // TODO Auto-generated constructor stub
  40. }
  41.  
  42. @Override
  43. public void onCreate(SQLiteDatabase db) {
  44. // TODO Auto-generated method stub
  45. db.execSQL(SCRIPT_CREATE_DATABASE);
  46. }
  47.  
  48. @Override
  49. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  50. // TODO Auto-generated method stub
  51.  
  52. }
  53.  
  54. }
  55.  
  56. public class MainActivity extends Activity {
  57.  
  58.  
  59. public static final String MYDATABASE_NAMEE = "MY_DATABASE_TEST";
  60. public static final int MYDATABASE_VERSION = 3;
  61. public static final String MYDATABASE_TABLE = "Stripclubs_table_test";
  62. public static final String KEY_ID = "_id";
  63. public static final String KEY_CONTENT1 = "Name";
  64. public static final String KEY_CONTENT2 = "Town";
  65. public static final String KEY_CONTENT3 = "State";
  66. public static final String KEY_CONTENT4 = "Phone";
  67. public static final String KEY_CONTENT5 = "Website";
  68. public static final String KEY_CONTENT6 = "Description";
  69. public static final String KEY_CONTENT7 = "Stars";
  70. public static final String KEY_CONTENT8 = "Latitude";
  71. public static final String KEY_CONTENT9 = "Longitude";
  72. public static final String KEY_CONTENT10 = "zipcode";
  73. public static final String KEY_CONTENT11 = "id";
  74.  
  75. private SQLite_helper sqLiteHelper;
  76. private SQLiteDatabase sqLiteDatabase;
  77. Cursor cursor;
  78.  
  79. @Override
  80. protected void onCreate(Bundle savedInstanceState) {
  81. super.onCreate(savedInstanceState);
  82. setContentView(R.layout.activity_main);
  83.  
  84.  
  85.  
  86. sqLiteHelper = new SQLite_helper(this, MYDATABASE_NAMEE, null, MYDATABASE_VERSION);
  87. sqLiteDatabase = sqLiteHelper.getWritableDatabase();
  88. if (!sqLiteDatabase.isOpen()) {
  89. sqLiteDatabase = getApplicationContext().openOrCreateDatabase("/data/data/com.example.sqlitetest/databases/MY_DATABASE_TEST.db", SQLiteDatabase.OPEN_READWRITE, null);
  90. }
  91. cursor = sqLiteDatabase.query(MYDATABASE_TABLE, null,null, null, null, null, null);
  92. System.out.println("MAX_PLACES "+cursor.getCount());
  93. for(int i=0;i<5;i++){
  94.  
  95. ContentValues cv = new ContentValues();
  96. cv.put(KEY_CONTENT1, "Salu");//Star Dust Lounge
  97. cv.put(KEY_CONTENT2, "place");//District Heights
  98. cv.put(KEY_CONTENT3, "fgfjhghj");
  99. cv.put(KEY_CONTENT4, "47567");//301-5344-159
  100. cv.put(KEY_CONTENT5, "ghj");//http://testsitez.info/stripclubs/harley-riders-private-club/
  101. cv.put(KEY_CONTENT6, "5xfdgh");//low key around the way spot. dancers will negotiate $$ for vip action.
  102. cv.put(KEY_CONTENT7, "3");
  103. cv.put(KEY_CONTENT8, "gh");//38.864
  104. cv.put(KEY_CONTENT9, "fggh");//-76.9145
  105. cv.put(KEY_CONTENT10, "gfh");
  106. cv.put(KEY_CONTENT11, "hjghj");
  107.  
  108. sqLiteDatabase.insert(MYDATABASE_TABLE, null, cv);
  109. cursor.requery();
  110. List<String> lables_name = sqLiteHelper.getAllLabels("Name");
  111. System.out.println(lables_name.size());
  112.  
  113. }
  114.  
  115. //new GetPlaces().execute("details");
  116.  
  117. }
  118. }
  119.  
  120. 08-13 10:34:34.829: E/AndroidRuntime(5860): FATAL EXCEPTION: main
  121. 08-13 10:34:34.829: E/AndroidRuntime(5860): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sqlitetest/com.example.sqlitetest.MainActivity}: java.lang.IllegalStateException: database not open
  122. 08-13 10:34:34.829: E/AndroidRuntime(5860): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
  123. 08-13 10:34:34.829: E/AndroidRuntime(5860): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
  124. 08-13 10:34:34.829: E/AndroidRuntime(5860): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
  125. 08-13 10:34:34.829: E/AndroidRuntime(5860): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
  126. 08-13 10:34:34.829: E/AndroidRuntime(5860): at android.os.Handler.dispatchMessage(Handler.java:99)
  127. 08-13 10:34:34.829: E/AndroidRuntime(5860): at android.os.Looper.loop(Looper.java:123)
  128. 08-13 10:34:34.829: E/AndroidRuntime(5860): at android.app.ActivityThread.main(ActivityThread.java:3683)
  129. 08-13 10:34:34.829: E/AndroidRuntime(5860): at java.lang.reflect.Method.invokeNative(Native Method)
  130. 08-13 10:34:34.829: E/AndroidRuntime(5860): at java.lang.reflect.Method.invoke(Method.java:507)
  131. 08-13 10:34:34.829: E/AndroidRuntime(5860): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  132. 08-13 10:34:34.829: E/AndroidRuntime(5860): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  133. 08-13 10:34:34.829: E/AndroidRuntime(5860): at dalvik.system.NativeStart.main(Native Method)
  134. 08-13 10:34:34.829: E/AndroidRuntime(5860): Caused by: java.lang.IllegalStateException: database not open
  135. 08-13 10:34:34.829: E/AndroidRuntime(5860): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1526)
  136. 08-13 10:34:34.829: E/AndroidRuntime(5860): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1426)
  137. 08-13 10:34:34.829: E/AndroidRuntime(5860): at com.example.sqlitetest.MainActivity.onCreate(MainActivity.java:85)
  138. 08-13 10:34:34.829: E/AndroidRuntime(5860): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  139. 08-13 10:34:34.829: E/AndroidRuntime(5860): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
  140. 08-13 10:34:34.829: E/AndroidRuntime(5860): ... 11 more
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement