promotional bannermobile promotional banner

EasyDB

Abandoned
Allows easy interfacing with MySQL for plugins

EasyDB is a developer tool that makes working with MySQL easier. I wrote this so all of my plugins could share the same MySQL database easily.

Installation

  1. Put the plugin in your plugins folder and run the plugin.
  2. Modify config.yml.
  3. Type /dbreload.

Now you are configured to use EasyDB! You can stop reading now.

Why EasyDB?

  • It uses prepared statements for everything, allowing your code to be safer.
  • It prevents you from writing a lot of try/catch statements
  • It has a Maven repository for you to use
  • It uses Apache DBUtils, a professional database library built for big and small applications
  • It enables you to write a lot less code to perform queries.

Maven Repository

To use this plugin as a dependency in your project, add the following to your pom.xml:

<repository> <id>nl-repo</id> <url>http://nexus.new-liberty.net/content/groups/public/&lt;/url&gt; </repository>

<dependency> <groupId>com.simplyian</groupId> <artifactId>easydb</artifactId> <version>0.1.0-SNAPSHOT</version> </dependency>

API

Source - Javadocs - Wiki

If you have any questions, feel free to add me on Skype - simplyianm.

The database object can be accessed with EasyDB.getDb(). This is the only object you need to start dealing with the database. Read the Javadocs for Database for in-depth information.

There are only 4 methods you need to know to do everything you would ever need.

boolean isValid()

Checks if the database connection is valid.

Example

if (db.isValid()) { getLogger().log(Level.INFO, "Database info is valid!"); }

void update(String query, Object... params)

Runs a database update.

Example

db.update("DELETE FROM bans WHERE player_name = ?", "albireox");

Since we are using prepared statements, you need to put ? marks where you would normally put the data in your queries then set the parameter after the query.

<T> T query(String query, ResultSetHandler<T> handler, Object... params)

Queries the database and returns the result.

Example

String name = db.query("SELECT firstname, lastname FROM people WHERE address = ?", new ResultSetHandler<String>{ @Override public String handle(ResultSet rs) { rs.next(); return rs.getString("firstname") + " " + rs.getString("lastname"); } });

Object get(String query, Object def, Object... params)

Gets one value from the database.

Example

int money = ((Integer) db.get("SELECT amount FROM money WHERE player = ?", 0, "albireox")).intValue();

The EasyDB Team

profile avatar
  • 2
    Projects
  • 2.7K
    Downloads

More from _ForgeUser6848146

  • CommandTimer project image

    CommandTimer

    • 1.7K
    • Bukkit Plugins

    A Cooldown for your needs

    • 1.7K
    • July 27, 2013
    • Bukkit Plugins
    • +1
  • Authoritas project image

    Authoritas

    • 1.9K
    • Bukkit Plugins

    An extremely simple permissions system.

    • 1.9K
    • November 17, 2011
    • Bukkit Plugins
    • +3
  • CommandTimer project image

    CommandTimer

    • 1.7K
    • Bukkit Plugins

    A Cooldown for your needs

    • 1.7K
    • July 27, 2013
    • Bukkit Plugins
    • +1
  • Authoritas project image

    Authoritas

    • 1.9K
    • Bukkit Plugins

    An extremely simple permissions system.

    • 1.9K
    • November 17, 2011
    • Bukkit Plugins
    • +3