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
|
package baie;
import java.io.*;
import java.lang.*;
import java.sql.*;
import javax.swing.*;
public class Connexion{
static private Connection con = null;
static boolean ok = true;
public static void main(String[] args){
ResultSet res=null;
Statement stm=null ;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ex) {
JOptionPane.showMessageDialog(null, " erreur de driver ");
ex.printStackTrace();
ok = false;
}
if (ok) { // driver ok - essai de connexion
try {
String login = "Admin";
String password = null;
String URL = "jdbc:odbc:logistique";
con = DriverManager.getConnection(URL, login, password);
stm=con.createStatement(); } catch (SQLException ex) {
JOptionPane.showMessageDialog(null, " erreur à la connexion ");
ex.printStackTrace();
ex.getMessage();
ok = false;
}
}
if (ok) {
JOptionPane.showMessageDialog(null, " bon ");
}
try{
boolean rs = stm.execute("SELECT * FROM Conteneur");
res=(ResultSet)stm.executeQuery("select * from Conteneur ");
if(rs){
res = stm.getResultSet();
System.out.println("A fiha ");
}else{
System.out.println("Il n'y a pas de ResultSet, peut-être une mise à jour : ");
int nbTuples = stm.getUpdateCount();
System.out.println("Nombre de tuples mis à jour = "+nbTuples);
}
System.out.println(rs );
}
catch(SQLException S){
System.out.println("fchkeeeeeel" );}
catch(NullPointerException N){
N.getStackTrace();
System.out.println("Erreur nullPointer sur le resultat");
}
try{
System.out.println(res.getFetchSize() );
System.out.println(res.getRow());
String S=res.getString(1);
}
catch(SQLException S){
S.getMessage();
S.getStackTrace();
System.out.println("hana");
}
catch(NullPointerException N){
N.getStackTrace();
N.getMessage();
System.out.println("Erreur nullPointer sur l'affichage");
}
catch(UnsupportedOperationException u){
u.getStackTrace();
}
System.out.println(res==null );
System.out.println(stm==null );
}} |