Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.circlepvp.mysql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import org.bukkit.entity.Player;
- public class MySQL {
- private static Connection connection;
- public void connect(String host, String database, String user, String password){
- if(!isConnected()){
- try {
- connection = DriverManager.getConnection(String.valueOf("jdbc:mysql://") + host + "/" + database, user, password);
- System.out.println("Bravo, la liaison s'est établie pour la taches!");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public void disconnect(){
- if(isConnected()){
- try{
- connection.close();
- System.out.println("Bravo, le system s'est déconnecté de la bdd !");
- } catch (SQLException e){
- e.printStackTrace();
- }
- }
- }
- private static boolean isConnected() {
- return false;
- }
- private Connection getConnection(){
- return connection;
- }
- public static void addtaches(String New){
- try {
- PreparedStatement insert = connection.prepareStatement("INSERT INTO taches(AddTaches) VALUES (?)");
- insert.setString (1, New);
- insert.execute();
- insert.close();
- } catch (SQLException e){
- e.printStackTrace();
- }
- }
- public void Player(Player player){
- try{
- PreparedStatement q = (PreparedStatement) connection.prepareStatement("INSERT INTO taches(Player) VALUES (?)");
- q.setString(1, player.getUniqueId().toString());
- q.execute();
- q.close();
- }catch (SQLException e){
- e.printStackTrace();
- }
- }
- public static String [] gettaches(){
- String [] result = new String [4];
- int i = 0;
- try {
- PreparedStatement insert = connection.prepareStatement("SELECT * FROM taches");
- ResultSet rs = insert.executeQuery();
- while (rs.next()) {
- result[i] = rs.getString("AddTaches");
- i++;
- }
- insert.close();
- return result;
- } catch (SQLException e){
- e.printStackTrace();
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement