Connexion Java avec plusieurs bases SQLite
Bonjour
j'ai plusieurs bases de données Boutique1.db, Boutique2.db, etc.
je voudrait pouvoir me connecter à ses différentes bases, comment modifier mon programme pour pouvoir selectionner la base désirée au moment de la connexion?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| public class Connexion {
private String DBPath ;
private Connection connexion = null ;
private Statement statement = null ;
public Connexion (String dBPath) {
DBPath = dBPath ;
}
public void connect() {
// Connexion à la base de données
try {
Class.forName("org.sqlite.JDBC") ;
connexion = DriverManager.getConnection("jdbc:sqlite:" + DBPath) ;
statement = connexion.createStatement() ;
System.out.println("Connexion à " + DBPath + " avec succès") ;
} catch (ClassNotFoundException notFoundException) {
notFoundException.printStackTrace() ;
System.out.println("Erreur de connexion") ;
} catch (SQLException sqlException) {
sqlException.printStackTrace() ;
System.out.println("Erreur de connexion") ;
}
}
} |