SQLibrary
I would highly suggest using Bukkit's plugin databases API instead of this plugin.
SQLibrary
SQLibrary was taken over from alta189 by PatPeter. So far it has support for 13 databases, a factory, and one query builder.
Tutorial
First, add these elements to your pom.xml if you're using Maven:
<repository> <id>dakani</id> <name>Dakani Nexus Repo</name> <url>http://repo.dakanilabs.com/content/repositories/public</url> </repository> <dependency> <groupId>lib.PatPeter.SQLibrary</groupId> <artifactId>SQLibrary</artifactId> <version>7.1</version> </dependency>
You should always save implementations to a superclass, unless that child class has more functionality. So, start off by creating your variable:
private Database sql;
Constructing your database object can be either hardcoded into the definition, or assigned in the method. The constructor does not automatically open the database connection so that it does not have to throw an SQLException (though this was considered for quite some time). Below are the constructors for the most popular databases: MySQL, SQLite, and H2.
sql = new MySQL(Logger.getLogger("Minecraft"), "[MyPlugin] ", "localhost", 3306, "myplugin", "minecraft", "password1"); sql = new SQLite(Logger.getLogger("Minecraft"), "[MyPlugin] ", this.getDataFolder().getAbsolutePath(), "MyPlugin", ".sqlite"); sql = new H2(Logger.getLogger("Minecraft"), "[MyPlugin] ", this.getDataFolder().getAbsolutePath(), "MyPlugin", ".h2");
For SQLite and H2, the extension is optional but will default to ".db". For MySQL, the hostname and port number are optional, but will default to those values. Next, we need to open our database connection:
if (sql.open()) { // ... }
If you know that your plugin will only use the database intermittently, you should check to see if it is open first:
if (!sql.isOpen()) { sql.open(); }
If any errors occur while opening the database connection, they will print to console.
Supported Databases
- Firebird
- FrontBase
- DB2
- H2
- Informix
- Ingres
- MaxDB
- MicrosoftSQL
- MySQL
- Mongo
- mSQL
- Oracle
- Ovrimos
- PostgreSQL
- SQLite
Installation
- Download the jar.
- In Eclipse, go to Project Properties ==> Java Build Path ==> Add External Jar and add SQLibrary.jar.
- Tell your users to install SQLibrary.jar along with your plugin
Do not install from source!
If you install SQLibrary directly into your plugin, the following bad things will occur:
- You cannot run your plugin alongside SQLibrary.jar plugins. Bukkit will (usually) find the SQLibrary classes in your plugin first, and block the SQLibrary.jar dependency.
- You cannot run your plugin alongside other plugins using SQLibrary directly from source. Same issue.
- Updating will definitely cause these problems and cause you much pain.
Download SQLibrary from your plugin
You can now place this code in your plugin to download and load SQLibrary from your plugin at runtime:
http://dev.bukkit.org/bukkit-plugins/sqlibrary/pages/soft-dependency-download/
Special Thanks
- alta189, for starting this library.
- Belphemur, for adding the first version of our factory package.
- omwah, for adding Maven to SQLibrary.
- moose51789, for adding Spout support.
- Mitsugaru, for hosting our Maven repository, finding bugs, and making fixes.
- max9403, for supplying the code to download SQLibrary at runtime.
I'm using cclogger which requires sqlite but with 1.9 things seem broken. Internal error.
@Mitsugaru
No problem. I just wanted to notify you. Thank you very much.
@games647
Sorry, there was a restart by the host (Linode) for some planned upgrades. Just needed to start the service afterwards and it slipped my mind. It should be up now, sorry for the downtime.
@PatPeter
Your repository is down. Could you restart it?
@moose517
Do you have the JDBC driver for Mongo and have you placed it in the lib directory of your server? I was trying to get this plugin to do this (another reason I made it a plugin instead of a source package), but I don't believe I ever got it working.
@CraftBang
H2 is faster than SQLite. I know that for a fact. SQLite is a more universal format though.
@Razorax
If I could +1 your comment I would Razorax. Gave me quite a chuckle.
I've done a lot of research into this Ebeans ORM that's built into Bukkit, and to be honest an ORM was what I wanted SQLibrary to become. You can see that in the query builders I had started to develop when I actively maintained this plugin.
It is based on this research that I believe every Minecraft plugin developer should learn how JPA generation works (which will look very good on a resume as well) and use Ebeans for a database layer.
Who is the "I" in "I would highly suggest using Bukkit's plugin databases API instead of this plugin."? Is it a Bukkit Nazi Dev? Or is it the author/current maintainer of this plugin?
@julib5432112345
Why's it need one? It works fine on craftbukkit and spigot?
Why no update?
@CraftBang
MySQL can (and often does) run on same machine. And if you have a website on the same box then that can read from the same MySQL.
So there are a lot of database types your plugin supports.. I can't choose which one to use, I would like to save the data on disk (not online), so MySQL is already gone. Which one would you prefer to be the fastest/best?
Thanks in advance
Anyone used mongo at all that can tell me what else is needed for it to work. Get seror that class not found for jdbc.mongod
Since I had this problem, I thought post it. The dependency tags for Maven are wrong in the post.
This is the updated version.
@Amunak
Yeah, works for me.
Did anyone confirm if this works on Spigot 1.8 on Java 8?
I understand nothing of this thing!
@SableDnah
using spigot 1.7.10 with the latest bps patch, and using carbon for 1.8 items it wont load, but when i use it on a server using purely 1649 it works perfectly
@broluigi Java 1.8 or MC 1.8?
This works find in the spigot 1649+ builds for me.
@Mitsugaru
Can you send me a version of sqlibrary that works on 1.8! We need your plugin for legendquest to work on our servers! I would gladly donate if possible