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.
@Favorlock
If your Java file is in UTF-8 encoding and your database is in UTF-8 encoding, it should work. The library has nothing in it that would filter UTF-8 characters into ?s.
Alternatively, you could use the Java syntax for Unicode symbols that exists for backwards compatibility, i.e. \u2764.
Is there a way I can send a string in UTF8 format. I'm having issues with the characters converting to "?", which prevents me from doing what I'd like to do.
The help forum is now the best place to look for help in regards to SQLibrary: http://dev.bukkit.org/server-mods/sqlibrary/forum/help/
@jaaaaaaaaaaack
You mean the implicit caching only available on the Oracle driver?
@EstJoel
https://github.com/PatPeter/SQLibrary/blob/master/lib/PatPeter/SQLibrary/Database.java
That's your best bet.
@EstJoel
checkTable() has been replaced by isTable(), and createTable() should be replaced with query() (since createTable() was providing no function difference or benefit) until I've created the Table query builder class that will allow you to dynamically build tables.
@Edge209 @sirmyllox
You guys have a PM.
As of v4.0, check/createTable (SQLite) is deprectated. I might have missed something, but what's the replacement now?
@Edge209
from my server log http://pastebin.com/87eNymLn
Hi. I have been using your library for quite a while with mixed results. Up until the latest release of my MC plugin I had a version of sqlibrary interal to my build structure, but was running into probelms with it becoming out of date. Also time to time I would see conflicts with other plugins also using your library.
So I have moved to requireing server owners to put your sqlibrary.jar into their plugin directory, and have removed the interal (out of date version). Now, I have a couple of server owners that are getting the following error during startup, but the majority are not seeing this and I dont see it on my test sysetm.
I don't know what to suggest to work around it. They say they have the sqlibrary.jar installed, I have it as a soft depend so my plugin loads afterward. (Do you think its possible that even though there is a soft dependancy that sqlibrary has not completed its initialization before my plugin tries to use it? )
Thanks in advance for you help!
Is there a quick reference that explains all important methods?
Hello friend. How can I disable "ImplicitCaching" in your library ? Statements are cached automatically.
@An___Idiot might if he's bored waiting for Supply and Demand to be released.
@hakelimopu Yeah, sorry about that. At the time I needed SQLibrary approved as a plugin ASAP, so I picked the first licensing option. The license details should be updated.
Using source code is perfectly fine and supported as it says above. If you have any methods you need for SQLite or anything you see wrong in the driver please notify me. I will make the change as fast as possible.
Here's my confusion:
You appear to have a rather restrictive license(All rights reserved), and yet provide the source code. Seems a little weird to me.
However, I am glad to see this library, as my own DB persistence lib uses SQLite exclusively, and which I had been considering expanding it, I'd much rather use something off the shelf like this.
My method of use will likely be from source code, and built in to my final jar, because I like to release single comprehensive jar files, rather than having to ship multiple files.
Then, of course, is the process of migrating my plugins to use this, but so it goes.
Hi, Could you please make a video about this? i get the concept, but following the instructions gets me nowhere, and for once in my life google-ing hasn't helped. Thank you, An_Idiot