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
   |  
public static void creerBaseDeDonnees(String nom) {
        String url = "jdbc:postgresql://localhost:5432/" + DEFAULT_BDD;
        Statement st = null;
        try {
            Connection co = connecter(DEFAULT_BDD, DEFAULT_USER, DEFAULT_MDP);
            st = co.createStatement();
            String requete = "CREATE DATABASE " + nom + ";";
            st.executeUpdate(requete);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            ClassMain.global.debug("On cloture !");
            if (st != null) {
                try {
                    st.close();
                } catch (SQLException e) {
                }
            }
        }
    }
public static void creerUtilisateur(String pseudo, String mdp) {
        String url = "jdbc:postgresql://localhost:5432/" + DEFAULT_BDD;
        Statement st = null;
        try {
            Connection co = DriverManager.getConnection(url, DEFAULT_USER, DEFAULT_MDP);
            st = co.createStatement();
            pseudo = pseudo.toLowerCase();
            String requete = "CREATE USER " + pseudo + " WITH PASSWORD '" + mdp + "';";
            st.executeUpdate(requete);
            requete = "ALTER DATABASE mabdd_" + pseudo +" OWNER TO " + pseudo +";";
            st.executeUpdate(requete);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            if (st != null) {
                try {
                    st.close();
                } catch (SQLException e) {
                }
            }
 
        }
    }
public static void rendreProprietaire(String pseudo, String database) {
        String url = "jdbc:postgresql://localhost:5432/" + DEFAULT_BDD;
        Statement st = null;
        try {
            Connection co = DriverManager.getConnection(url, DEFAULT_USER, DEFAULT_MDP);
            st = co.createStatement();
            pseudo = pseudo.toLowerCase();
            String requete = "ALTER DATABASE " + database +" OWNER TO " + pseudo +";";
            st.executeUpdate(requete);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            ClassMain.global.debug("On cloture !");
            if (st != null) {
                try {
                    st.close();
                } catch (SQLException e) {
                }
            }
 
        }
    } | 
Partager