Sueta

LuckySQL API

1.2.2

Easy MySQL / SQLite API

·Plugin

About
Make you life easier working with database! This library will help you to handle MySQL or SQLite databases in a simple way and with less code.

Examples

Connecting to database

Without API

try {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection connection = DriverManager.getConnection("jdbc:mysql://" + url + "/" + name + "?user=" + user + "&password=" + pass + "&autoReconnect=true&useSSL=false");
} catch (Exception ex) {...}

With API

MySQL mysql = new MySQL(url, name, user, pass);
mysql.openConnection();
Executing an update

Without API

Statement statement = null;
try {
    if (connection.isClosed()) {...};
    statement = connection.createStatement();
    statement.executeUpdate(sql);
} catch (SQLException ex) {...}

With API

mysql.executeUpdate(sql);

Features

  • Simple and easy to use
  • MySQL and SQLite
  • Prepare and store statements
  • Manual commit / rollback ability
  • JavaDocs and Source code included

Getting started
For example we need to work with MySQL. First, we need to create MySQL object and open a connection:

MySQL mysql = new MySQL("127.0.0.1:3306", "name", "user", "password");
mysql.openConnection();

Then we can execute any update or query:

ResultSet set = mysql.executeQuery("SELECT COUNT(*) FROM database");

No needs to check if ResultSet empty etc. Method returns null if there are no entries.
Library also gives you ability to prepare and store statements to execute it many times in future. Firstly we create prepared statement:

mysql.prepareStatement("mySt", "SELECT * FROM database WHERE col = ?");

So, now we can execute it, replaing '?' by variable:

mysql.executePreparedQuery("mySt", "value");

Similar projects

Plugin →