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.
Problem for using java8u20, reccomended version java is 7u22 or first 8.0(same as 7u22 but 8.0 readdy)
I' am getting an error:
[13:59:23 INFO]: [SQLibrary] Loading SQLibrary v7.1 [13:59:23 INFO]: [Tials-Core] Loading Tials-Core v3.7 [13:59:23 INFO]: [SQLibrary] Enabling SQLibrary v7.1 [13:59:23 INFO]: SQLibrary loaded. [13:59:23 INFO]: [Tials-Core] Enabling Tials-Core v3.7 [13:59:23 ERROR]: [MyPlugin][H2] H2 driver class missing: org.h2.D river.
And my code:
public static Database database;
public void onEnable() { database = new lib.PatPeter.SQLibrary.H2(Logger.getLogger("Minecraft"), "[MyPlugin]", this.getDataFolder().getAbsolutePath(), "MyPlugin", ".h2"); database.open(); }
SqlLibary is in the Build Path as Libary and is in the plugin Folder....
@Mitsugaru
I tried bukkit 1.7.10 builds same thing happens. It only happens when I add SQLibrary.
Send me your paypal and a link to the 1.7.10 build in pm please :D. I'll test it out and send you a reward if it solves the problem.
PS: Basically what is happening is Skript uses sqlibrary for sql database connections. Skript itself runs fine in 1.7.10 and can store in alternative databases on 1.7.10 with no issue. But as soon as I add SQLibrary and have a moderate size mysql database (I lowered it from over 300,000 rows to 22,000 rows. still won't work) the server freezes as it tries to slowly load the sql database. In bukkit builds prior to 1.7.10 the database loads within a few seconds. After 1.7.10 it seems to load a few rows every few seconds, which is extremely slow.
@wiedzmin137
Have you done a null check on the player or sql objects?
@selfservice0
My question is: what steps have you taken to determine that the library is at fault and not the specific implementation, Cauldron? Have you tested other plugins that utilize the library to have similar slow downs?
@selfservice0
Appears to build fine for 1.7.10 without any code changes.
If someone is willing/able to update this to work with 1.7.10 please message me I am more than willing to compensate for your hard.
The github repositories is here: https://github.com/PatPeter/SQLibrary
this does not work properly with any of the cauldron 1.7.10 builds. Pulls sql data very slowly http://files.minecraftforge.net/Cauldron/
Hello. I have problem with NullPointerException at this line:
Do you know what is reason of that error?
@Mitsugaru
Awesome, will do just that. thanks :)
@SableDnah
Well, the best I can do is build a fork that should compile in Java 6 and host it on my Jenkins.
Tell them to try the jar here and see if it works (haven't tested it).
EDIT: Changed build to explicitly use OpenJDK 6, so, have them use at the latest build and hopefully that will work.
@Mitsugaru
BTW sorry for the sudden influx of LegendQuest users - I didn't expect it to be so popular so fast!
@Mitsugaru
Some of the big MC server providers are still on 1.6 (I know!) so sometimes the admins don't have a choice. If I could I'd say J7+ only myself - but have to cater to demand.
@SableDnah
SQLibrary is currently built using Java 7. However, you can try and compile it using Java 6, as I don't believe it uses anything specifically in Java 7 at the moment.
That being said, is there a reason why users cannot upgrade to Java 7?
@PippaSmith
If you're a server admin trying to use a plugin that uses SQLibrary, all you need is to include the SQLibrary.jar in the server's plugin folder.
If you're a developer, you need to include SQLibrary as a dependency and include it in your project's classpath. Then you have to create and manage your database and queries via the objects it provides.
If you're talking about having your plugin grab SQLibrary on server enable... well, its not recommended by BukkitDev and you shouldn't be doing it. Instead, you should be telling your users that your plugin requires SQLibrary and they should download it themselves.
Does it mean we need to place the code into the plugin that we wish to use it with, for example LegendQuest, which I am wanting to try?
Ditto Zalakoth
How do you "install with a plugin?"
Hi @PatPeter, Im getting people with
org.bukkit.plugin.InvalidPluginException: java.lang.UnsupportedClassVersionError: lib/PatPeter/SQLibrary/SQLibrary : Unsupported major.minor version 51.0
Does SQLibrary require Java7? Or can it be compiled ok for J6?
@Squwkers13: You can take a look at my GitHub project called Statistics, that will show you a few queries along with the way to extract & use the results.
This is the class that has all of my SQLite stuff - queries along with the rest. https://github.com/Etsija/Statistics/blob/master/src/com/github/etsija/statistics/SqlFuncs.java
@PatPeter
There's no code in the query builders, and I was hoping to find some example queries to look at...
And I know I write them as strings! But where do I use those strings?
You don't write queries in Java, you write them as Strings. Unless you mean the Select query builder, which is kind of still an alpha.
You can browse the source here, that's better than JavaDoc:
https://github.com/PatPeter/SQLibrary