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
| import java.sql.*;
import java.io.*;
public class articles1{
static final String DB="base";
public static void main(String arg[]){
Connection connect=null;
Statement S=null;
ResultSet RS=null;
try{
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
System.out.println("Where is your Oracle JDBC Driver?");
e.printStackTrace();
return;
}
System.out.println("Oracle JDBC Driver Registered!");
try {
connect=DriverManager.getConnection("jdbc:oracle:thin@:localhost:1521:base","login","mdp");
} catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
return;
}
System.out.println("Connexion avec la base " + DB + " établie");
S=connect.createStatement();
RS=S.executeQuery("select * from ARTICLES");
while(RS.next()){ // tant qu'il y a une ligne à exploiter
System.out.println(RS.getString("code")+","+
RS.getString("nom")+","+
RS.getString("prix")+","+
RS.getString("stock_actu")+","+
RS.getString("stock_mini"));
}
} catch (Exception e){
erreur("Erreur " + e,2);
}
try{
connect.close();
System.out.println("Base " + DB + " fermée");
} catch (Exception e){}
}
public static void erreur(String msg, int exitCode){
System.err.println(msg);
System.exit(exitCode);
}
} |