Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.flashback083.config;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import com.mysql.jdbc.Connection;
- import fr.flashback083.proxy.CommonProxy;
- import net.minecraftforge.common.config.Configuration;
- public class SQL {
- public static SQL sql;
- public java.sql.Connection connection;
- private String urlbase, host, database, user, pass;
- Configuration cfg = CommonProxy.configbdd;
- public SQL(String urlbase, String host, String database, String user, String pass){
- this.urlbase = "jdbc:mysql://";
- this.host = cfg.getCategory("Base de donnees").get("Host").getString();
- this.database = cfg.getCategory("Base de donnees").get("Database").getString();
- this.user = cfg.getCategory("Base de donnees").get("User").getString();
- this.pass = cfg.getCategory("Base de donnees").get("MDP").getString();
- }
- //Création de la table si non existante lors du lancement serveur
- public Connection connection() {
- if(!this.isConnected()) {
- try {
- connection = DriverManager.getConnection(urlbase + host + "/" + database, user, pass);
- System.out.println("connexion a la BDD reussi");
- createTable();
- } catch (SQLException var2) {
- var2.printStackTrace();
- }
- }
- return null;
- }
- //Simple déconnection
- public Connection deconnection() {
- if(this.isConnected()) {
- try {
- this.connection.close();
- System.out.println("BDD deconnecter");
- } catch (SQLException var2) {
- var2.printStackTrace();
- }
- }
- return null;
- }
- //Création de la table si non existante.
- public void createTable() throws SQLException {
- String gtm = "CREATE TABLE IF NOT EXISTS GTM"
- + " (ID INTEGER default 0,"
- + " PseudoV VARCHAR(20),"
- + " Type VARCHAR(10),"
- + " Nom VARCHAR(50),"
- + " Objet VARCHAR(2500),"
- + " Quantity INTEGER default 1,"
- + " PokeD INTEGER default 0,"
- + " PointsB INTEGER default 0,"
- + " Etat INTEGER default 0,"
- + " Date INTEGER,"
- + " PseudoA VARCHAR(20),"
- + " PRIMARY KEY (ID))";
- java.sql.Statement stmt = this.connection.createStatement();
- stmt.execute(gtm);
- }
- //Boolean
- public boolean isConnected() {
- return this.connection != null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement