promotional bannermobile promotional banner

SQL API

MySQL API for Bukkit

Ever needed to interact with a MySQL database but have no experience? Then this library is for you!

Connecting to a database

SQL sql = new SQL("database", "ip", "username", "password");

Setting the active table

sql.setTable("table name");

Executing statements

sql.execute(statement);

Statements

Select statement: get a value from the active table

// this example gets an integer from the database, in a table called Users where the username is Steve
SelectStatement<Integer> statement = new SelectStatement<Integer>("gems", new Clause("Username", "'Steve'"), 0);
int value = sql.execute(statement);

UpdateStatement: update a column value in a table

// this example sets the integer in the Users table for when the Username is Steve
UpdateStatement statement = new UpdateStatement(new Clause("Username", "'Steve'"), new Clause("gems", "100", "SET"));
sql.execute(statement);

DeleteStatement: delete a row from the current table

// this example deletes the row where the Username is Steve
DeleteStatement statement = new DeleteStatement(new Clause("Username", "'Steve'"));
sql.execute(statement);

InsertStatement: insert a row into the current table

// this code inserts a record for the Username Steve with 100 gems
InsertStatement statement = new InsertStatement("'Steve', 100");
sql.execute(statement);

CountStatement: count the number of records with 100 gems

// this code counts the number of rows with 100 as the gems value
CountStatement statement = new CountStatement(new Clause("gems", "100"));
int number = sql.execute(statement);

ReadTableStatement: mainly for debugging, prints a given column value of every row in a table

// this example prints the all the usernames in the given table
ReadTableStatement statement = new ReadTableStatement("Username");
sql.execute(statement);

CreateTableStatement: create a table.

CreateTableStatement statement = new CreateTableStatement(new TableArgument("Username", "VARCHAR(18)", "UNIQUE NOT NULL"), new TableArgument("gems", "INT(255)"));
sql.execute(statement);

You can also create custom statements by implementing the Statement<T> interface.

The SQL API Team

profile avatar
  • 17
    Projects
  • 45.1K
    Downloads

More from _ForgeUser11591311View all

  • FriendMe project image

    FriendMe

    • 32.9K
    • Bukkit Plugins

    FriendMe

    • 32.9K
    • April 16, 2015
    • Bukkit Plugins
    • +1
  • Mine Chatter project image

    Mine Chatter

    • 571
    • Bukkit Plugins

    Mine Chatter

    • 571
    • March 9, 2014
    • Bukkit Plugins
  • TeamAPI project image

    TeamAPI

    • 0
    • Bukkit Plugins

    Want to make simple minigames but aren't familiar with instances and constructors? Then this is the API for you!

    • 0
    • February 13, 2014
    • Bukkit Plugins
  • Firework API project image

    Firework API

    • 0
    • Bukkit Plugins

    Want to easily spawn fireworks without using lengthy builders? Then FireworkAPI is for you!

    • 0
    • February 13, 2014
    • Bukkit Plugins
  • FriendMe project image

    FriendMe

    • 32.9K
    • Bukkit Plugins

    FriendMe

    • 32.9K
    • April 16, 2015
    • Bukkit Plugins
    • +1
  • Mine Chatter project image

    Mine Chatter

    • 571
    • Bukkit Plugins

    Mine Chatter

    • 571
    • March 9, 2014
    • Bukkit Plugins
  • TeamAPI project image

    TeamAPI

    • 0
    • Bukkit Plugins

    Want to make simple minigames but aren't familiar with instances and constructors? Then this is the API for you!

    • 0
    • February 13, 2014
    • Bukkit Plugins
  • Firework API project image

    Firework API

    • 0
    • Bukkit Plugins

    Want to easily spawn fireworks without using lengthy builders? Then FireworkAPI is for you!

    • 0
    • February 13, 2014
    • Bukkit Plugins