Guest User

Untitled

a guest
Dec 17th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. public void onCreate(SQLiteDatabase db) {
  2. db.execSQL("create table users(id int(2) primary key,name varchar(20),last_name varchar(20),email varchar(40),password varchar(16))");
  3. db.execSQL("create table books(id int(10) primary key,name varchar(20),type varchar(20),editorial varchar(20),aƱo date,author varchar(40),stock int (2))");
  4. }
  5.  
  6. private void books_default(){
  7. AdminSQLiteOpenHelper admin = new
  8. AdminSQLiteOpenHelper(getApplicationContext(),"books",null,1);
  9. SQLiteDatabase bd = admin.getWritableDatabase();
  10. cursor = bd.rawQuery("INSERT INTO books (name,author) values ('Quijote','Cervantes')",null);
  11. Toast.makeText(getApplicationContext(),"Libros Creados" ,
  12. Toast.LENGTH_SHORT).show();
  13. bd.close();
  14. cursor.close();
  15. createBookList();
  16.  
  17. }
  18.  
  19. private void createBookList() {
  20. booksList = new ArrayList<>();
  21. Books item;
  22. AdminSQLiteOpenHelper admin = new AdminSQLiteOpenHelper(getApplicationContext(),"books",null,1);
  23. SQLiteDatabase bd = admin.getReadableDatabase();
  24. String q = "SELECT name,author FROM books";
  25. cursor1 = bd.rawQuery(q,null);
  26.  
  27.  
  28. if (cursor1.moveToFirst()){
  29. do {
  30. item = new Books();
  31. item.setBookName(cursor1.getString(0));
  32. item.setAuthor(cursor1.getString(1));
  33. booksList.add(item);
  34. } while (cursor1.moveToNext());
  35. cursor1.close();
  36. bd.close();
  37. }else{
  38. Toast.makeText(getApplicationContext(),"No hay libros" , Toast.LENGTH_SHORT).show();
  39. bd.close();
  40. }
  41.  
  42.  
  43. }
Add Comment
Please, Sign In to add comment