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
|
// Enregistrement d'un client dans la bd
import java.sql.*;
class Lst_Client{
//Lst_Client(){}
public static void main(String[] args) throws SQLException{
String url = "jdbc:oracle:thin:@localhost:1521:oracle"; // port=1521 en général
String utilisateur = args[0];
String mdp = args[1];
int nb_col;
String sql = "select * from client";
Connection connexion = null;
try{
Class.forName("oracle.jdbc.OracleDriver");
connexion = DriverManager.getConnection(url, utilisateur, mdp);
Statement requete = connexion.createStatement();
ResultSet resultat = requete.executeQuery(sql);
catch(SQLException sqle){
System.out.println("La requête contient une erreur !");
}
catch(ClassNotFoundException cnfe){
System.out.println("La classe n'est pas trouvée.");
}
catch(Exception e){
System.out.println("Autre type d'erreur dans le programme : ");
e.printStackTrace();
}
finally{
if(connexion!=null){
try{connexion.close();
}
catch(Exception e){
e.printStackTrace();
}
}
}
}
} |
Partager