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 26 27 28 29 30 31 32 33 34 35
|
public void connect( String log, String pass)
{
try{
FileInputStream f = new FileInputStream ("oracle.properties");
Properties p = new Properties ();
p.load (f);
try
{
try{
//Recherche du pilote pour un SGBD Oracle
Class.forName(p.getProperty ("jdbc.driver")).newInstance();
}//Capture de l'exception
catch (Exception ex){
//Message d'erreur
JOptionPane.showMessageDialog(null,ex,"Connexion",JOptionPane.WARNING_MESSAGE);
}
//Connection à la base de données
//Connection conn = DriverManager.getConnection(pilote + log + "/" + pass + url);
Connection conn = DriverManager.getConnection(p.getProperty ("jdbc.url"),log ,pass);
//Création d'un statement
stmt = conn.createStatement();
}//Capture d'une erreur du type SQLException
catch ( SQLException E)
{ //Affichage d'un message d'erreur
JOptionPane.showMessageDialog(null,E,"Connexion",JOptionPane.WARNING_MESSAGE);
}
}
catch (Exception e) {
System.out.println(e.toString());
}
} |