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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| public static void main(String[] args) throws SQLException{
// TODO Auto-generated method stub
// === Decarations ===
String tabOracle [] = new String [5];
String nom = null;
String ordreSelect = "select * from pers where nompers = '"+nom+"'";
String driv = null;
String conn = null;
String messErCon = null;
String messErSte = null;
String mesConOK = null;
String mesSteOK = null;
String messfin = null;
String messErdon = null;
Connection connexion = null;
String donneePers []= new String [10];
// === Prise du nom ===
System.out.println("un nom: ");
nom = Lire.Chaine();
//=== Recuperation des messages ===
try {
LireIni recDonnees = new LireIni();
recDonnees.lire("test.ini");
tabOracle[0] = recDonnees.getProperty("driver");
//System.out.println(tabOracle[0]);
tabOracle[1] = recDonnees.getProperty("connection");
//System.out.println(tabOracle[1]);
tabOracle[2] = recDonnees.getProperty("erreur1");
tabOracle[3] = recDonnees.getProperty("erreur2");
tabOracle[4] = recDonnees.getProperty("finProg");
mesConOK = recDonnees.getProperty("conOK");
mesSteOK = recDonnees.getProperty("steOK");
messErdon = recDonnees.getProperty("erreur3");
} catch (Exception e) {
// TODO: handle exception
System.out.println("!!!!! Erreur de recuperation des Messages !!!!!");
System.out.println(e.getMessage());
System.out.println(e.getCause());
}
//=== affectation aux variables ===
driv = tabOracle[0];
// System.out.println(driv);
conn = tabOracle[1];
messErCon = tabOracle[2];
messErSte = tabOracle[3];
messfin = tabOracle[4];
// === Connexion ===
try {
Class.forName(driv);
connexion = DriverManager.getConnection(conn);
System.out.println(mesConOK);
} catch (Exception e) {
// TODO: handle exception
System.out.println(messErCon);
System.out.println(e.getCause());
System.out.println(e.getStackTrace());
System.out.println(e.getLocalizedMessage());
}
// === Statement ===
ResultSet res1 = null;
try {
Statement stmt1 = connexion.createStatement();
res1 = stmt1.executeQuery(ordreSelect);
System.out.println(mesSteOK);
} catch (SQLException i) {
// TODO: handle exception
System.out.println(messErSte);
System.out.println(i.getErrorCode());
System.out.println(i.getCause());
}
try {
res1.next();
donneePers[0] = res1.getString("nompers");
donneePers[1] = res1.getString("prepers");
donneePers[2] = res1.getString("datnaiss");
donneePers[3] = res1.getString("teldom");
donneePers[4] = res1.getString("telport");
res1.close();
connexion.close();
} catch (SQLException e) {
// TODO: handle exception
System.out.println("RATE !!!!!");
System.out.println("ERREUR N°: "+e.getErrorCode());
System.out.println("CAUSE: "+e.getCause());
System.out.println("MESSAGE ORA: "+e.getMessage());
}
// === Affichage des Donnees ===
System.out.println("Résultats: ");
System.out.println("|"+donneePers[0]+" | "+donneePers[1]+" | "+donneePers[2]+" | "+donneePers[3]+" | "+donneePers[4]+" |");
// === Fin ===
System.out.println(messfin);
} |
Partager