Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaBeans;
- import gestionErreurs.TraitementException;
- import java.math.BigDecimal;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- public class BOperations {
- private String noDeCompte;
- private String nom;
- private String prenom;
- private BigDecimal solde;
- private Connection connect;
- private ResultSet set;
- private BigDecimal ancienSolde;
- private BigDecimal nouveauSolde;
- private String op;
- private BigDecimal valeur;
- private String dateInf;
- private String dateSup;
- private ArrayList<ArrayList<String>> operationsParDates;
- public String getNoDeCompte() {
- return noDeCompte;
- }
- public void setNoDeCompte(String noDeCompte) {
- this.noDeCompte = noDeCompte;
- }
- public String getNom() {
- return nom;
- }
- public String getPrenom() {
- return prenom;
- }
- public BigDecimal getSolde() {
- return solde;
- }
- public BigDecimal getAncienSolde() {
- return ancienSolde;
- }
- public BigDecimal getNouveauSolde() {
- return nouveauSolde;
- }
- public String getOp() {
- return op;
- }
- public String getValeur() {
- return String.valueOf(valeur);
- }
- public void setOp(String op) {
- this.op = op;
- }
- public void setValeur(String valeur) {
- this.valeur = new BigDecimal(valeur);
- }
- public String getDateInf() {
- return dateInf;
- }
- public String getDateSup() {
- return dateSup;
- }
- public ArrayList<ArrayList<String>> getOperationsParDates() {
- return operationsParDates;
- }
- public void setDateInf(String dateInf) {
- this.dateInf = dateInf;
- }
- public void setDateSup(String dateSup) {
- this.dateSup = dateSup;
- }
- public void ouvrirConnexion() throws TraitementException{
- try {
- connect = DriverManager.getConnection(
- "jdbc:mysql://sqletud.univ-mlv.fr/vtissero_db?user=vtissero&password=dD5oabey");
- } catch (SQLException e) {
- throw new TraitementException("3");
- }
- }
- public void fermerConnexion(){
- try {
- connect.close();
- } catch (SQLException e) {
- System.out.println("Problème lors de la fermeture");
- }
- }
- public void consulter() throws TraitementException{
- Statement statement;
- try {
- statement = connect.createStatement();
- set = statement.executeQuery("select * from COMPTE where NOCOMPTE='"+noDeCompte+"'");
- set.next();
- nom = set.getString("NOM");
- } catch (SQLException e) {
- throw new TraitementException("21");
- }
- }
- public void traiter() throws TraitementException{
- Statement statement;
- try {
- statement = connect.createStatement();
- set = statement.executeQuery("select * from COMPTE where NOCOMPTE='"+noDeCompte+"'");
- set.next();
- ancienSolde = set.getBigDecimal("SOLDE");
- if(op == "+"){
- nouveauSolde = ancienSolde.add(valeur);
- }
- else{
- nouveauSolde = ancienSolde.subtract(valeur);
- }
- if(nouveauSolde.signum() < 0){
- throw new TraitementException("24");
- }
- else{
- System.out.println("Modification du compte ...");
- statement.executeUpdate("update COMPTE set SOLDE="+nouveauSolde+"where NOCOMPTE='"+noDeCompte+"'");
- statement.executeUpdate("insert into OPERATION(NOCOMPTE,DATE,HEURE,OP,VALEUR) values('"+noDeCompte+"',CURRENT_DATE,CURRENT_TIME,'"+op+"','"+valeur+"')");
- System.out.println("Modification OK");
- }
- } catch (SQLException e) {
- throw new TraitementException("21");
- }
- solde = nouveauSolde;
- }
- public void listerParDates() throws TraitementException{
- ArrayList<String> liste = new ArrayList<String>();
- operationsParDates = new ArrayList<ArrayList<String>>();
- Statement statement;
- try {
- statement = connect.createStatement();
- set = statement.executeQuery("select * from OPERATION where DATE BETWEEN '"+dateInf+"' and '"+dateSup+"' and NOCOMPTE='"+noDeCompte+"'");
- while(set.next() == true){
- liste.add(set.getDate("DATE").toString());
- liste.add(set.getString("OP"));
- liste.add(String.valueOf(set.getFloat("VALEUR")));
- operationsParDates.add(liste);
- }
- System.out.println(operationsParDates);
- } catch (SQLException e) {
- throw new TraitementException("21");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement