Package dao

Source Code of dao.DaoPariHistorique

package dao;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import business.PariHistorique;


public class DaoPariHistorique {
  /* ------------------------------------------------ REQUETES PRECOMPILEES */
  private static CallableStatement statementGetPariHistorique = null;
  private static CallableStatement statementGetParisHistorique = null;


  /* --------------------------------------------------------- CONSTRUCTEUR */
  static {
    try {
      statementGetPariHistorique = DbConnection.getInstance().prepareCall("{call getPariHistorique(?)}");
      statementGetParisHistorique = DbConnection.getInstance().prepareCall("{call getParisHistorique(?)}");
    }
    catch(SQLException e) {
      e.printStackTrace();
    }
  }


  /* -------------------------------------------------------------- METHODE */
  public static PariHistorique getPariHistorique(int id_pariHistorique) {
    PariHistorique pariHistorique = null;
   
    try {
      ResultSet rs = null;
     
      synchronized(statementGetPariHistorique) {
        statementGetPariHistorique.setInt(1, id_pariHistorique);
       
        rs = statementGetPariHistorique.executeQuery();
      }
     
      if(rs != null && rs.last()) {
        if(rs.getRow() == 1) {
          pariHistorique = new PariHistorique(
              rs.getInt("id_pariHistorique"),
              rs.getInt("fk_id_utilisateur"),
              rs.getString("nomTrain"),
              rs.getString("nomGarePassage"),
              rs.getString("nomGareDestination"),
              rs.getTimestamp("heurePassageTrain"),
              rs.getInt("mise"),
              rs.getInt("retard"),
              rs.getTimestamp("heurePari"),
              rs.getInt("gain"));
        }
        else {
          System.err.println("DaoPariHistorique.getPariHistorique(" + id_pariHistorique + ") : plusieurs résultats.");
        }
      }
      else {
        System.err.println("DaoPariHistorique.getPariHistorique(" + id_pariHistorique + ") : aucun résultat.");
      }
    }
    catch(SQLException e) {
      e.printStackTrace();
     
      return null;
    }
   
    return pariHistorique;
  }
 

  public static List<PariHistorique> getParisHistorique(int id_utilisateur) {
    List<PariHistorique> parisHistorique = null;
   
    try {
      ResultSet rs = null;
     
      synchronized (statementGetParisHistorique) {
        statementGetParisHistorique.setInt(1, id_utilisateur);
       
        rs = statementGetParisHistorique.executeQuery();
      }
     
      if(rs != null) {
        parisHistorique = new ArrayList<PariHistorique>();
       
        while(rs.next()) {
          parisHistorique.add(new PariHistorique(
              rs.getInt("id_pariHistorique"),
              rs.getInt("fk_id_utilisateur"),
              rs.getString("nomTrain"),
              rs.getString("nomGarePassage"),
              rs.getString("nomGareDestination"),
              rs.getTimestamp("heurePassageTrain"),
              rs.getInt("mise"),
              rs.getInt("retard"),
              rs.getTimestamp("heurePari"),
              rs.getInt("gain")));
        }
      }
    }
    catch(SQLException e) {
      e.printStackTrace();
     
      return null;
    }
   
    return parisHistorique;
  }
}
TOP

Related Classes of dao.DaoPariHistorique

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.