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</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

  1. Firebird
  2. FrontBase
  3. DB2
  4. H2
  5. Informix
  6. Ingres
  7. MaxDB
  8. MicrosoftSQL
  9. MySQL
  10. Mongo
  11. mSQL
  12. Oracle
  13. Ovrimos
  14. PostgreSQL
  15. SQLite

Installation

  1. Download the jar.
  2. In Eclipse, go to Project Properties ==> Java Build Path ==> Add External Jar and add SQLibrary.jar.
  3. 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:

  1. 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.
  2. You cannot run your plugin alongside other plugins using SQLibrary directly from source. Same issue.
  3. 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.

You must login to post a comment. Don't have an account? Register to get one!

  • Avatar of SableDnah SableDnah Apr 30, 2015 at 16:07 UTC - 0 likes

    @julib5432112345: Go

    Why's it need one? It works fine on craftbukkit and spigot?

    "All this technology and it still takes forever to get anywhere" [ Donate ] [ Twitter ]

    Mob HealthLegendQuest
    Mob Health: Simple damage reporting.LegendQuest: Complete RPG plugin.
  • Avatar of julib5432112345 julib5432112345 Apr 30, 2015 at 16:00 UTC - 0 likes

    Why no update?

  • Avatar of SableDnah SableDnah Apr 29, 2015 at 12:39 UTC - 0 likes

    @CraftBang: Go

    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.

  • Avatar of CraftBang CraftBang Apr 29, 2015 at 11:26 UTC - 0 likes

    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

    Last edited Apr 29, 2015 by CraftBang
  • Avatar of moose517 moose517 Mar 11, 2015 at 01:48 UTC - 0 likes

    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

  • Avatar of funnygatt funnygatt Feb 13, 2015 at 11:33 UTC - 0 likes

    Since I had this problem, I thought post it. The dependency tags for Maven are wrong in the post.

             <dependency>
                <groupId>lib.PatPeter.SQLibrary</groupId>
                <artifactId>SQLibrary</artifactId>
                <version>7.1</version>
            </dependency>
    

    This is the updated version.

    Quote from portapipe: Go

    Guys don't make funnygatt mad! C'mon! Well... he's quite right...

    Quote from portapipe: Go

    Sorry but funnygatt is right :|

    Quote from Him:

    Funnygatt is King. Once you've figured that out, there is nothing you can't understand.

  • Avatar of SableDnah SableDnah Feb 03, 2015 at 19:40 UTC - 0 likes

    @Amunak: Go

    Yeah, works for me.

  • Avatar of Amunak Amunak Feb 03, 2015 at 12:46 UTC - 0 likes

    Did anyone confirm if this works on Spigot 1.8 on Java 8?

  • Avatar of nashoxx nashoxx Dec 25, 2014 at 19:26 UTC - 1 like

    I understand nothing of this thing!

  • Avatar of broluigi broluigi Nov 16, 2014 at 01:09 UTC - 0 likes

    @SableDnah: Go

    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

    16.11 16:05:55 [Server] INFO ... 6 more
    16.11 16:05:55 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) ~[SpigotServer.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    16.11 16:05:55 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[SpigotServer.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    16.11 16:05:55 [Server] INFO at java.lang.Class.newInstance(Class.java:374) ~[?:1.7.0_51]
    16.11 16:05:55 [Server] INFO at java.lang.reflect.Constructor.newInstance(Constructor.java:526) ~[?:1.7.0_51]
    16.11 16:05:55 [Server] INFO at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.7.0_51]
    16.11 16:05:55 [Server] INFO at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) ~[?:1.7.0_51]
    16.11 16:05:55 [Server] INFO at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.7.0_51]
    16.11 16:05:55 [Server] INFO at com.addemod.itsatacoshop.motd.PersonalMOTD.<init>(PersonalMOTD.java:25) ~[?:?]
    16.11 16:05:55 [Server] INFO at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[SpigotServer.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    16.11 16:05:55 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:125) ~[SpigotServer.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    16.11 16:05:55 [Server] INFO Caused by: java.lang.IllegalStateException: Initial initialization
    16.11 16:05:55 [Server] INFO ... 6 more
    16.11 16:05:55 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) ~[SpigotServer.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    16.11 16:05:55 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[SpigotServer.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    16.11 16:05:55 [Server] INFO at java.lang.Class.newInstance(Class.java:374) ~[?:1.7.0_51]
    16.11 16:05:55 [Server] INFO at java.lang.reflect.Constructor.newInstance(Constructor.java:526) ~[?:1.7.0_51]
    16.11 16:05:55 [Server] INFO at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.7.0_51]
    16.11 16:05:55 [Server] INFO at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) ~[?:1.7.0_51]
    16.11 16:05:55 [Server] INFO at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.7.0_51]
    16.11 16:05:55 [Server] INFO at lib.PatPeter.SQLibrary.SQLibrary.<init>(SQLibrary.java:12) ~[?:?]
    16.11 16:05:55 [Server] INFO at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[SpigotServer.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    16.11 16:05:55 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:122) ~[SpigotServer.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    16.11 16:05:55 [Server] INFO Caused by: java.lang.IllegalArgumentException: Plugin already initialized!
    16.11 16:05:55 [Server] INFO at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [SpigotServer.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    16.11 16:05:55 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:458) [SpigotServer.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    16.11 16:05:55 [Server] INFO at net.minecraft.server.v1_7_R4.DedicatedServer.init(DedicatedServer.java:152) [SpigotServer.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    16.11 16:05:55 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugins(CraftServer.java:369) [SpigotServer.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    16.11 16:05:55 [Server] INFO at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:258) [SpigotServer.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    16.11 16:05:55 [Server] INFO at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:336) ~[SpigotServer.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    16.11 16:05:55 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:133) ~[SpigotServer.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    16.11 16:05:55 [Server] INFO org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: Plugin already initialized!
    16.11 16:05:55 [Server] INFO [16:05:55 ERROR]: Could not load 'plugins/SQLibrary.jar' in folder 'plugins'
    16.11 16:05:55 [Server] INFO [16:05:55 INFO]: Set PluginClassLoader as parallel capabl
    
    Last edited Nov 16, 2014 by broluigi

    TownyMc

    Website: lorecase.org

Facts

Date created
Aug 25, 2012
Categories
Last update
Jan 14, 2014
Development stage
Release
Language
  • enUS
License
Creative Commons — Attribution-NonCommercial-NoDerivs 3.0 Unported (CC BY-NC-ND 3.0)
Curse link
SQLibrary
Downloads
41,097
Recent files

Authors