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
| package Historique;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DataBase {
String driver = "oracle.jdbc.driver.OracleDriver";
String login = "XXXX";
String password = "XXXX";
String url = "XXXX";
protected Connection connection = null;
Statement stmt;
protected ResultSet rs;
short persoID;
String[] resultat;
protected int stat;
protected long seuil;
public DataBase(int select, String requete)
{
try{
Class.forName(driver);
connection = DriverManager.getConnection(url,login,password);
stmt = connection.createStatement();
switch(select)
{
case 1: this.writeBDD(requete);break;
case 2: this.readBDD(requete);break;
}
System.out.println("la");
}
catch(ClassNotFoundException cnfe){
System.out.println("Driver introuvable : ");
cnfe.printStackTrace();
}
catch(SQLException sqle){
System.out.println("Erreur SQL : "+sqle);
//Cf. Comment gérer les erreurs ?
}
catch(Exception e){
System.out.println("Autre erreur : ");
e.printStackTrace();
}
}
/*
* Insertion des donnéees
*/
public void writeBDD(String requete)
{
try
{
stmt.executeUpdate(requete);
System.out.println("Requete executée");
String commit = "COMMIT";
stmt.executeUpdate(commit);
System.out.println("Requete validée");
if(connection!=null)
{
connection.close();
}
}
catch(SQLException sqle){
System.out.println("Erreur SQL : "+sqle);
}
}
/*
* Selection des données
*/
public void readBDD(String vue)
{
try
{
rs = stmt.executeQuery(vue);
System.out.println("Requete executée");
}
catch(SQLException sqle){
System.out.println("Erreur SQL : "+sqle);
}
}
} |
Partager