Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import oracle.jdbc.*;
- public class ConnectionBD
- {
- public Connection conn;
- public ConnectionBD()
- {
- try
- {
- Class.forName("oracle.jdbc.driver.OracleDriver");
- // Driver chargé
- }
- catch(ClassNotFoundException e)
- {
- System.out.println(e);
- }
- // Local
- //String url = "jdbc:oracle:thin:@172.17.200.251:1521:orcl";
- // Distant
- String url = "jdbc:oracle:thin:@205.237.246.251:1521:orcl";
- String user = "DITULLIO";
- String mpd = "oracle";
- try
- {
- conn = DriverManager.getConnection(url,user,mpd);
- System.out.println("Vous êtes connecté à la BD");
- }
- catch(SQLException e)
- {
- System.out.println(e);
- }
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////// MÉTHODES POUR LES JOUEURS //////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- public void AjouterJoueur(String Pseudo, String NomJoueur, String PrenomJoueur)
- {
- try
- {
- CallableStatement Stm = conn.prepareCall("{ call GESTIONJOUEURS.AJOUTERJOUEUR(?,?,?)}");
- Stm.setString(1, Pseudo);
- Stm.setString(2, NomJoueur);
- Stm.setString(3, PrenomJoueur);
- Stm.executeUpdate();
- }
- catch(SQLException e){System.out.println(e);}
- }
- public void SupprimerJoueur(String Pseudo)
- {
- try
- {
- CallableStatement Stm = conn.prepareCall("{ call GESTIONJOUEURS.SUPPRIMERJOUEUR(?)}");
- Stm.setString(1, Pseudo);
- Stm.executeUpdate();
- }
- catch(SQLException e){System.out.println(e);}
- }
- public void InitialiserPosition(int NumeroTour,String Pseudo,int PositionX,int PositionY)
- {
- try
- {
- CallableStatement Stm = conn.prepareCall("{ call GESTIONJOUEURS.INITIALISERPOSITION(?, ?, ?, ?)}");
- Stm.setInt(1, NumeroTour);
- Stm.setString(2, Pseudo);
- Stm.setInt(3, PositionX);
- Stm.setInt(4,PositionY);
- Stm.executeUpdate();
- }
- catch(SQLException e){System.out.println(e);}
- }
- public void ModifierPosition(int NumeroTour,String Pseudo,int PositionX,int PositionY)
- {
- try
- {
- CallableStatement Stm = conn.prepareCall("{ call GESTIONJOUEURS.MODIFIERPOSITION(?, ?, ?, ?)}");
- Stm.setInt(1, NumeroTour);
- Stm.setString(2, Pseudo);
- Stm.setInt(3, PositionX);
- Stm.setInt(4,PositionY);
- Stm.executeUpdate();
- }
- catch(SQLException e){System.out.println(e);}
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////// MÉTHODES POUR LA PARTIE //////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- public void InitialiserTout()
- {
- try
- {
- CallableStatement Stm =conn.prepareCall("{ call GESTIONPARTIE.Initialisertout() }");
- Stm.executeUpdate();
- }
- catch(Exception e){System.out.println(e);}
- }
- public void AjouterScore(char CodeCat,String Pseudo)// a chaque bonne reponse
- {
- try
- {
- CallableStatement Stm = conn.prepareCall("{ call GESTIONPARTIE.AJOUTERSCORE(?,?)}");
- Stm.setObject(1, CodeCat);
- Stm.setString(2, Pseudo);
- Stm.executeUpdate();
- }
- catch(SQLException e){System.out.println(e);}
- }
- public void SetQuestionRepondue(String Statut , String NumeroQuestion) //une fois répondu, je doit setter ca
- {
- try
- {
- CallableStatement Stm = conn.prepareCall("{ call GESTIONPARTIE.QUESTIONREPONDUE(?,?)}");
- Stm.setString(1, Statut);
- Stm.setString(2, NumeroQuestion);
- Stm.executeUpdate();
- }
- catch(SQLException e){System.out.println(e);}
- }
- public void VerifierReponse(String NumeroReponse) // J'envoie: V01A Renvoie Y pour Yes et N
- {
- try
- {
- CallableStatement Stm = conn.prepareCall("{ call GESTIONPARTIE.VERIFIERREPONSE('" + NumeroReponse + "')}");
- Stm.registerOutParameter(1, OracleTypes.CHAR);
- Stm.execute();
- Stm.executeUpdate();
- }
- catch(SQLException e){System.out.println(e);}
- }
- public int CompterQuestionsRestantes(String Categorie) //appeler automatiquement
- {
- int NombreNonRepondues=0;
- try
- {
- CallableStatement stm3 =conn.prepareCall("{ ? = call GESTIONPARTIE.CompterQuestions('" + Categorie + "') }");
- stm3.registerOutParameter(1, OracleTypes.INTEGER);
- stm3.execute();
- NombreNonRepondues = stm3.getInt(1);
- }
- catch(Exception e){System.out.println(e);}
- return NombreNonRepondues;
- }
- public void ObtenirQuestion(String Categorie) // Ex: "V" , "B" , "R" , "J", si pu de questions, ca renvoie rien
- {
- boolean Valide=false;
- int Random = 0;
- String Statut = null;
- int NbRestantes = CompterQuestionsRestantes(Categorie);
- String NumQuestion = null;
- if(NbRestantes > 0)
- {
- while(!Valide)
- {
- Random = (int)(Math.random() * (20+1-1)) + 1;
- if(Random <= 1 && Random < 10)
- {
- NumQuestion = Categorie + "0" + Random;
- }
- else
- {
- NumQuestion = Categorie + Random;
- }
- try
- {
- CallableStatement Stm =conn.prepareCall("{ ? = call GESTIONPARTIE.verifierrepondue('" + NumQuestion + "') }");
- Stm.registerOutParameter(1, OracleTypes.CHAR);
- Stm.execute();
- Statut = Stm.getString(1);
- if(Statut.equals("N"))
- {
- Valide = true;
- }
- }
- catch(Exception e){System.out.println(e);}
- }
- // Avec le numéro de la question trouvée , il va chercher les 4 choix de cette question
- try
- {
- String Choix1;
- // String Choix2;
- // String Choix3;
- // String Choix4;
- CallableStatement Stm2 = conn.prepareCall("{ ? = call GESTIONPARTIE.ObtenirChoixReponses('" + NumQuestion + "') }",
- ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
- Stm2.registerOutParameter(1, OracleTypes.CURSOR);
- Stm2.execute();
- ResultSet rest = (ResultSet) Stm2.getObject(1);
- while(rest.next())
- {
- // Reste à faire : Envoyer les choix un par un au client
- Choix1 = rest.getString(1);
- //A: salut B: kdskd C:dsdskd D:dksgkd
- }
- }
- catch(Exception e){System.out.println(e);}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement