Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to open many database?
    primarykey
    data
    text
    <p>I've many BDD file. i want to open the first, extract data, and close, open the 2nd, extarct data, close, etc...</p> <p>I want do something like this in my Main. </p> <pre><code> LivresBDD livreBdd = new LivresBDD(this); // open the 1st BDD livreBdd.open(); Livre livreFromBdd = livreBdd.getLivreWithTitre(livre.getTitre()); //extract data livreBdd.close(); // open the 2nd BDD livreBdd.open(); Livre livreFromBdd = livreBdd.getLivreWithTitre(livre.getTitre()); //extract data livreBdd.close(); </code></pre> <p>LivreBDD.java:</p> <pre><code>public class LivresBDD { private static final int VERSION_BDD = 1; private static final String NOM_BDD = "eleves.db"; private static final String TABLE_LIVRES = "table_livres"; private static final String COL_ID = "ID"; private static final int NUM_COL_ID = 0; private static final String COL_ISBN = "ISBN"; private static final int NUM_COL_ISBN = 1; private static final String COL_TITRE = "Titre"; private static final int NUM_COL_TITRE = 2; private SQLiteDatabase bdd; private MaBaseSQLite maBaseSQLite; public LivresBDD(Context context){ //e //On créer la BDD et sa table maBaseSQLite = new MaBaseSQLite(context, NOM_BDD, null, VERSION_BDD); } public void open(){ //on ouvre la BDD en écriture bdd = maBaseSQLite.getWritableDatabase(); } public void close(){ //on ferme l'accès à la BDD bdd.close(); } public Livre getLivreWithTitre(String titre){ Cursor c = bdd.query(TABLE_LIVRES, new String[] {COL_ID, COL_ISBN, COL_TITRE}, COL_TITRE + " LIKE \"" + titre +"\"", null, null, null, null); return cursorToLivre(c); } //Cette méthode permet de convertir un cursor en un livre private Livre cursorToLivre(Cursor c){ //si aucun élément n'a été retourné dans la requête, on renvoie null if (c.getCount() == 0) return null; //Sinon on se place sur le premier élément c.moveToFirst(); //On créé un livre Livre livre = new Livre(); //on lui affecte toutes les infos grâce aux infos contenues dans le Cursor livre.setId(c.getInt(NUM_COL_ID)); livre.settype_t(c.getString(NUM_COL_TYPE_T)); livre.setnum_question(c.getString(NUM_COL_NUM_QUESTION)); livre.setquestion(c.getString(NUM_COL_QUESTION)); //On ferme le cursor c.close(); //On retourne le livre return livre; } } </code></pre> <p>It's the same BDD wich open a each time, but how can i specify the BDD name i want to open? Srry i'm newbee ;)</p> <p>Edit: I've done this:</p> <pre><code> LivresBDD livreBdd = new LivresBDD(this,BDD_NAME1); //Création d'une instance de ma classe LivresBDD livreBdd.open(); [...] livreBdd.close(); LivresBDD livreBdd = new LivresBDD(this,BDD_NAME2); //Création d'une instance de ma classe LivresBDD livreBdd.open(); [...] livreBdd.close(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload