A tool based on mysql-connector to simplify the use of databases, tables & columns

Related tags

Database EasySQL
Overview

Description

A tool based on mysql-connector to simplify the use of databases, tables & columns. This tool automatically creates the databases & tables if they do not already exist ; so you don't have to create them manually.

If you have any problem, DM me on discord (nz#1337)

Developers

You can reuse EasySQL but make sure you comply with the LICENSE.

Maven

<dependencies>
    <dependency>
        <groupId>com.easysql</groupId>
        <artifactId>EasySQL</artifactId>
        <version>1.0.0</version>
    </dependency>
</dependencies>

Usage

Simple configure connection & database

EasySQL easySQL = new EasySQL();
easySQL.setHost("127.0.0.1");
easySQL.setPort(3306);
easySQL.setUser("root");
easySQL.setPassword("password");
easySQL.setDatabase("demo");

Add specific tables

//First table
Table playerTable = new Table("players");
playerTable.setPrimaryKey("uuid");
playerTable.addColumn("uuid", "VARCHAR(36)");
playerTable.addColumn("kills", "INTEGER");
playerTable.addColumn("deaths", "INTEGER");

//Second table
Table demoTable = new Table("demo2");
demoTable.setPrimaryKey("uuid");
demoTable.addColumn("uuid", "VARCHAR(36)");
demoTable.addColumn("totalConnections", "INTEGER");

//Create the tables if they do not exist
easySQL.createDefaultTables(playerTable, demoTable); //Here you can enter the number of tables you want 

As you can see above, you can use "int" instead of "INTEGER", "string" instead of "VARCHAR(255)", "double" instead of "DOUBLE" and more. But you can also insert the default types like "INTEGER", "VARCHAR(36)"...

Etablish connection

easySQL.connect();

Close connection

easySQL.close();

Delete database

easySQL.delete();

Delete table

playerTable.delete();

Insert default VALUES

Column column = playerTable.getColumns();
column.insertDefault("cdb4810e-b975-4fbd-97be-3aa838a017aa", 0, 0); //uuid, kills, deaths --> see above to understand the order of values

Edit values (replacement)

column.editValue("uuid", "cdb4810e-b975-4fbd-97be-3aa838a017aa", "kills", 2)

Check if value exists in specific column

if(column.isExists("uuid", "cdb4810e-b975-4fbd-97be-3aa838a017aa")) {
  System.out.println("Yes !");
} else {
  System.out.println("No !");
}

Getting value

System.out.println("Kills : " + column.getValue("uuid", "cdb4810e-b975-4fbd-97be-3aa838a017aa", "kills"));

Returning Kills : 2

Get table name

System.out.println("Table name : " + column.getTableName());

Returning Table name : players

Remove row in column

column.delete("uuid", "cdb4810e-b975-4fbd-97be-3aa838a017aa");

Simple example for bukkit

In this example, if the player who connects does not have a profile in the database, plugin will create one for him.

Then, for each broken block, add 1 to "blocks" in database and print that value.

import com.nz1337.easysql.*;
import com.nz1337.easysql.manager.*;
import org.bukkit.event.*;
import org.bukkit.event.block.*;
import org.bukkit.event.player.*;
import org.bukkit.plugin.java.*;

public class Test extends JavaPlugin implements Listener {

    private Column column;

    public void onEnable() {
        this.getServer().getPluginManager().registerEvents(this, this);
        createDatabase();
    }

    private void createDatabase() {
        Table table = new Table("breaked").setPrimaryKey("uuid").addColumn("uuid", "VARCHAR(36)").addColumn("blocks", "INTEGER");
        EasySQL easySQL = new EasySQL();
        easySQL.setHost("127.0.0.1");
        easySQL.setPort(3306);
        easySQL.setUser("root");
        easySQL.setPassword("password");
        easySQL.setDatabase("server");
        easySQL.createDefaultTables(table);
        easySQL.connect();
        this.column = table.getColumns();
    }

    @EventHandler
    public void onConnect(PlayerJoinEvent event) {
        String uuid = event.getPlayer().getUniqueId().toString();
        this.column.insertDefault(uuid, 0);
    }

    @EventHandler
    public void onBreak(BlockBreakEvent event) {
        String uuid = event.getPlayer().getUniqueId().toString();
        int oldBreakedBlocks = (int) this.column.getValue("uuid", uuid, "blocks");
        System.out.println("Old value for " + uuid + " : " + oldBreakedBlocks);
        this.column.editValue("uuid", uuid, "blocks", oldBreakedBlocks + 1);
        int newbreakedBlocks = (int) this.column.getValue("uuid", uuid, "blocks");
        System.out.println("New value for " + uuid + " : " + newbreakedBlocks);
    }
}

After use :

You might also like...

Free universal database tool and SQL client

Free universal database tool and SQL client

DBeaver Free multi-platform database tool for developers, SQL programmers, database administrators and analysts. Supports any database which has JDBC

Jan 1, 2023

Database Subsetting and Relational Data Browsing Tool.

Database Subsetting and Relational Data Browsing Tool.

Jailer Database Tool Jailer is a tool for database subsetting and relational data browsing. The Subsetter exports consistent, referentially intact row

Jan 7, 2023

MapDB provides concurrent Maps, Sets and Queues backed by disk storage or off-heap-memory. It is a fast and easy to use embedded Java database engine.

MapDB: database engine MapDB combines embedded database engine and Java collections. It is free under Apache 2 license. MapDB is flexible and can be u

Dec 30, 2022

MapDB provides concurrent Maps, Sets and Queues backed by disk storage or off-heap-memory. It is a fast and easy to use embedded Java database engine.

MapDB: database engine MapDB combines embedded database engine and Java collections. It is free under Apache 2 license. MapDB is flexible and can be u

Jan 1, 2023

A Gradle plugin that improves the experience when developing Android apps, especially system tools, that use hidden APIs.

HiddenApiRefinePlugin A Gradle plugin that improves the experience when developing Android apps, especially system tools, that use hidden APIs. Backgr

Jan 5, 2023

Easy-es - easy use for elastich search

Easy-es - easy use for elastich search

Born To Simplify Development What is Easy-Es? Easy-Es is a powerfully enhanced toolkit of RestHighLevelClient for simplify development. This toolkit p

Jan 6, 2023

BenDB - An fastest, qualified & easy to use multi database library

BenDB - An fastest, qualified & easy to use multi database library

BenDB - An fastest, qualified & easy to use multi database library

May 3, 2022

requery - modern SQL based query & persistence for Java / Kotlin / Android

requery - modern SQL based query & persistence for Java / Kotlin / Android

A light but powerful object mapping and SQL generator for Java/Kotlin/Android with RxJava and Java 8 support. Easily map to or create databases, perfo

Jan 5, 2023
Releases(v1.0.3)
Owner
nz
x
nz
Amazon AppFlow Custom JDBC Connector example

Amazon AppFlow Custom JDBC Connector example This project contains source code and supporting files that implements Amazon Custom Connector SDK and re

AWS Samples 6 Oct 26, 2022
Flink Connector for Apache Doris(incubating)

Flink Connector for Apache Doris (incubating) Flink Doris Connector More information about compilation and usage, please visit Flink Doris Connector L

The Apache Software Foundation 115 Dec 20, 2022
flink-connector-redis

github: https://github.com/future94/flink-connector-redis gitee : https://gitee.com/future94/flink-connector-redis Stargazers over time 为什么写这个项目 对比其他的

invalley 3 Aug 30, 2022
Change data capture for a variety of databases. Please log issues at https://issues.redhat.com/browse/DBZ.

Copyright Debezium Authors. Licensed under the Apache License, Version 2.0. The Antlr grammars within the debezium-ddl-parser module are licensed unde

Debezium 7.9k Dec 26, 2022
Mystral (pronounced "Mistral") is an efficient library to deal with relational databases quickly.

Mystral An efficient library to deal with relational databases quickly. A little request: read the Javadoc to understand how these elements work in de

null 13 Jan 4, 2023
EBQuery allows you to easily access databases through a REST API.

EBQuery Table of Contents Introduction - Enterprise Backend as a Service Requirements Getting started Using EBQuery Features Introduction - Enterprise

null 15 Nov 9, 2021
Java & Kotlin Async DataBase Driver for MySQL and PostgreSQL written in Kotlin

jasync-sql is a Simple, Netty based, asynchronous, performant and reliable database drivers for PostgreSQL and MySQL written in Kotlin. Show your ❤ wi

null 1.5k Dec 31, 2022
SPRING MySQL Database Connection using JDBC STEPS

SPRING-MySQL-Database-Connection-using-JDBC-STEPS SPRING MySQL Database Connection using JDBC STEPS Step1: Create maven project Group id: com.cdac Art

Dnyaneshwar Madhewad 1 Jan 27, 2022
Apache Ant is a Java-based build tool.

Apache Ant What is it? ----------- Ant is a Java based build tool. In theory it is kind of like "make" without makes wrinkles and with

The Apache Software Foundation 355 Dec 22, 2022
HasorDB is a Full-featured database access tool, Providing object mapping,Richer type handling than Mybatis, Dynamic SQL

HasorDB is a Full-featured database access tool, Providing object mapping,Richer type handling than Mybatis, Dynamic SQL, stored procedures, more dialect 20+, nested transactions, multiple data sources, conditional constructors, INSERT strategies, multiple statements/multiple results. And compatible with Spring and MyBatis usage.

赵永春 17 Oct 27, 2022