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 int GetScore(String PseudoJoueur)
- {
- int NbScore=0;
- try
- {
- CallableStatement stm3 =conn.prepareCall("{ ? = call GESTIONJOUEURS.GETSCORE('" + PseudoJoueur + "') }");
- stm3.registerOutParameter(1, OracleTypes.INTEGER);
- stm3.execute();
- NbScore = stm3.getInt(1);
- }
- catch(Exception e){System.out.println(e) ;}
- return NbScore;
- }
- public void AjouterScore( char CodeCat,String Pseudo)// a chaque bonne reponse
- {
- try
- {
- System.out.println("CodeCat: " + CodeCat + " Pseudo: " + Pseudo);
- CallableStatement Stm = conn.prepareCall("{call GESTIONPARTIE.AJOUTERSCORE('" + CodeCat + "','" + Pseudo + "')}");
- //String temp = String.valueOf(CodeCat);
- 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 String VerifierReponse(String NumeroReponse) // J'envoie: V01A Renvoie Y pour Yes et N
- {
- try
- {
- CallableStatement Stm = conn.prepareCall("{ ? = call GESTIONPARTIE.VERIFIERREPONSE('" + NumeroReponse + "')}");
- System.out.println(NumeroReponse);
- Stm.registerOutParameter(1, OracleTypes.CHAR);
- Stm.execute();
- Stm.executeUpdate();
- String reponse = Stm.getString(1);
- return reponse;
- }
- catch(SQLException e)
- {
- System.out.println(e);
- return "erreur";
- }
- }
- 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 String ObtenirQuestion(String Categorie) // Ex: "V" , "B" , "R" , "J"
- {
- boolean Valide=false;
- int Random = 0;
- String Statut = null;
- int NbRestantes = 20;
- 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
- {
- System.out.println("Question choisie au hasard : " + NumQuestion);
- //NumQuestion = "V01";
- 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
- {
- // Appel de la fonction pour avoir l'énoncé de la question
- CallableStatement Stm1 = conn.prepareCall("{ ? = call GESTIONPARTIE.ObtenirQuestion('" + NumQuestion + "') }");
- Stm1.registerOutParameter(1, OracleTypes.VARCHAR);
- Stm1.execute();
- String Suite = ":" + Stm1.getString(1);
- // Appel de la fonction pour avoir les choix de réponses de la question
- 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);
- NumQuestion = NumQuestion + Suite + "|";
- int Cpt=1;
- while(rest.next())
- {
- System.out.println("debut du while");
- if(Cpt==1)
- NumQuestion = NumQuestion + "A[" + rest.getString(1) + "]";
- else if(Cpt==2)
- NumQuestion = NumQuestion + "B[" + rest.getString(1) + "]";
- else if(Cpt==3)
- NumQuestion = NumQuestion + "C[" + rest.getString(1) + "]";
- else if(Cpt==4)
- NumQuestion = NumQuestion + "D[" + rest.getString(1) + "]";
- Cpt++;
- }
- }
- catch(Exception e){System.out.println(e);}
- }
- return NumQuestion;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement