Advertisement
Guest User

DataAdapter.java

a guest
Jun 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. package com.example.johhnyfrog.myapplication;
  2.  
  3. import java.io.IOException;
  4. import android.content.Context;
  5. import android.database.Cursor;
  6. import android.database.SQLException;
  7. import android.database.sqlite.SQLiteDatabase;
  8. import android.util.Log;
  9.  
  10. public class DataAdapter
  11. {
  12. protected static final String TAG = "DataAdapter";
  13.  
  14. private final Context mContext;
  15. private SQLiteDatabase mDb;
  16. private DataBaseHelper mDbHelper;
  17.  
  18. public DataAdapter(Context context)
  19. {
  20. this.mContext = context;
  21. mDbHelper = new DataBaseHelper(mContext);
  22. }
  23.  
  24. public DataAdapter createDatabase() throws SQLException
  25. {
  26. try
  27. {
  28. mDbHelper.createDataBase();
  29. }
  30. catch (IOException mIOException)
  31. {
  32. Log.e(TAG, mIOException.toString() + " UnableToCreateDatabase");
  33. throw new Error("UnableToCreateDatabase");
  34. }
  35. return this;
  36. }
  37.  
  38. public DataAdapter open() throws SQLException
  39. {
  40. try
  41. {
  42. mDbHelper.openDataBase();
  43. mDbHelper.close();
  44. mDb = mDbHelper.getReadableDatabase();
  45. }
  46. catch (SQLException mSQLException)
  47. {
  48. Log.e(TAG, "open >>"+ mSQLException.toString());
  49. throw mSQLException;
  50. }
  51. return this;
  52. }
  53.  
  54. public void close()
  55. {
  56. mDbHelper.close();
  57. }
  58.  
  59. public Cursor getLibro(){
  60. Cursor libro=mDb.query(true,"domande",new String[]{"quesito","risposta1"},null,null,null,null,null,null);
  61. if (libro!=null) {
  62. libro.moveToFirst();
  63. return libro;
  64. }
  65. else{
  66. return null;
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement