Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.vexia.api.database;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class SqlManager {
- private String host, name, user, password;
- private Connection connection;
- public SqlManager(String host, String name, String user, String password){
- this.host = host;
- this.name = name;
- this.user = user;
- this.password = password;
- }
- public void connect() {
- if (!isConnected()) {
- try {
- this.connection = DriverManager.getConnection("jdbc:mysql://" + this.host + "/" + this.name,
- this.user, this.password);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public void disconnect() {
- if (isConnected()) {
- try {
- this.connection.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public void initTables(){
- try {
- this.connection.prepareStatement("CREATE TABLE IF NOT EXISTS `accounts` (`id` int(11) NOT NULL, `pseudo` varchar(255) DEFAULT NULL, `uuid` text, `ip` text, `grade` int(11) "
- + "NOT NULL DEFAULT '0',`coins` int(11) DEFAULT '0',`credit` int(11) NOT NULL DEFAULT '0',`firstJoin` bigint(20) NOT NULL DEFAULT '0',`lastJoin` bigint(20) "
- + "NOT NULL DEFAULT '0',`totalTime` bigint(20) NOT NULL DEFAULT '0',`friends` text,`online` tinyint(1) NOT NULL DEFAULT '0')").executeQuery();
- this.connection.prepareStatement("CREATE TABLE IF NOT EXISTS `ban` (`id` int(11) NOT NULL,`playerID` int(11) NOT NULL,`modoID` int(11) NOT NULL,"
- + "`type` enum('BAN','BANIP','MUTE','KICK') NOT NULL,`raison` text NOT NULL,`start` bigint(20) NOT NULL,`duration` bigint(20) NOT NULL,"
- + "`removeID` int(11) NOT NULL,`removeRaison` text NOT NULL)").executeQuery();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public boolean isConnected() {
- try {
- if ((this.connection == null) || (this.connection.isClosed()) || (!this.connection.isValid(5))) {
- return false;
- }
- return true;
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- public Connection getConnection() {
- return this.connection;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement