SQL API
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.
Comments