[LIB] SQLibrary - Database wrappers for all database engines

Discussion in 'Resources' started by PatPeter, Aug 27, 2011.

  1. Offline

    HSAR

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I'm with you there. My project has kind of stalled while I wait for this...
  2. Offline

    DrAgonmoray

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I figured out how to use it this morning, and it's working perfectly. I think I might be able to help you out, so gime yo' questions.
  3. Offline

    HSAR

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    So, um... I heard you can store data with this library?

    That's kind of the level I'm coming from. I figured I'd read through which functions did what and build myself up from there, but that's not really an option at the moment. I've gleaned enough from this thread to open up a connection and catch any errors that might be thrown, but that's the absolute limit of what I know about this right now.

    This post has been edited 1 time. It was last edited by HSAR Sep 17, 2011.
  4. Offline

    Kanlaki101

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    After about 6 hours of messing with it, I finally got a stable connection to my MySQL database.
    But I ended up finding an old plugin source and viewed how they did it.

    I used the MySQL Connector/J 5.1.17 and a MySQL tutorial.

    Connector:
    http://dev.mysql.com/downloads/connector/j/

    Tutorial:
    http://zetcode.com/databases/mysqljavatutorial/



    This is working for now, but I'm not sure for how long.
    Will this library work better for me than the above method?
  5. Offline

    Celtic Minstrel

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I believe the first of those two is included in the craftbukkit.jar. :p Anyway, this library probably won't really work much better; it may, however, be a little easier to use. Don't take my word for it though, because I haven't really looked at it.
  6. Offline

    PatPeter

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    First of all: Sorry everyone, university picked up and most of my Java has been going there along with my free time.

    That was a derp on my part, I was staring at the return statement (return null;) thinking, "I see no problem here, it's returning the variable "result", oh wait."

    Why pass to another function when you can just use conditionals?

    How about this: I'll consider making methods that can automate the creation of queries when the stupid library stops losing connection on Linux.

    "'void' type not allowed here"; I'll give you that voids are checked at compile time and nulls at runtime, but as stated, it would only be from function misuse.


    As said, I dropped PHP in the thread as food for thought, which it was: mission accomplished. If you have any specific functionality from PDO, feel free to mention it.

    Well my first priority has been to solve this stupid connection issue that I can't get my head around. After that I would then finish the tutorial program and maybe make a video.

    :( Sorry, things like this where hanging over my mind all week.

    Are you on Windows or Linux, and how did you get it working?

    http://forums.bukkit.org/threads/lib-tut-mysql-sqlite-bukkit-drivers.33849/#post-641927 Mini-tutorial?

    What do you mean when you say the above method? Are you literally including the jars from these files into your plugin?

    Link to old plugin source please?

    They're not included in the jar, they're downloaded to the ./lib folder in your main Minecraft directory.

    This post has been edited 1 time. It was last edited by PatPeter Sep 18, 2011.
  7. Offline

    HSAR

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
  8. Offline

    Kanlaki101

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    It's good to know that you just haven't abandoned it.
    Incorporating MySQL/SQLite into a plugin is one of the only things that don't have a written or video tutorial.

    This would be so helpful.
  9. Offline

    DrAgonmoray

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Err.. I'm on windows, the server is on linux. I used this code onEnable:
    PHP:
    mysql = new MySQL(logprefixhost"3306"dbuserpass);
    And I use these two methods I made:
    PHP:
        public int getCredits(String player) {
            try {
                
    ResultSet res mysql.query("SELECT coins FROM credits WHERE username='"+player+"';");
                if (
    res.first()) {
                    return 
    res.getInt("coins");
                }
                return 
    0;
            } catch (
    Exception e) {
                
    log.severe(prefix+"An error occured while fetching credits for player '"+player+"'");
                return 
    0;
            }
        }

        public 
    void changeCredis(String playerint amount) {
            try {
                
    mysql.query("UPDATE credits SET coins = coins +"+amount+" WHERE username='"+player+"';");
            } catch (
    Exception e) {
                
    log.severe(prefix+"An error occured while changing credits for player '"+player+"'");
                
    e.printStackTrace();
            }
        }
    It works perfect.
  10. Offline

    Celtic Minstrel

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Actually, the JDBC connectors for SQLite and MySQL are included in the craftbukkit.jar. Unzip it and see for yourself if you don't believe me. :)
  11. Offline

    alta189

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Celtic is right, that was why you didn't need the connector for my version of the SQL Library....
    CraftBukkit has it for the built in Database handling through eBeans
  12. Offline

    Kanlaki101

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Well good. That means no more editing my manifest file, which I guess now has been pointless this whole time.
  13. Offline

    MG127

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    why not adding basic functions to this?
    like:
    createTable(String tableName, List<String> columns, HashMap<String,String> columnDefs){
    String content="";
    for (int i=0;i<columns.size();i++){
    content=content+", "+columns.get(i)+" "+columnDefs.get(columns.get(i));
    }
    query("CREATE TABLE "+tableName+"("+content+");");

    This post has been edited 1 time. It was last edited by MG127 Sep 18, 2011.
  14. Offline

    Celtic Minstrel

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Honestly, I wish it didn't have it built-in, but no-one has listened to me on that point. <_<
  15. Offline

    Lolmewn BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I'd really like it if the API wasn't throwing all those Exceptions, but just try - catching it in-method. =D
  16. Offline

    PatPeter

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    How much SQL do you know independent of Java? SQL is better to learn on its own seeing that you'll use it no matter what language or API you switch to eventually.

    The problem is writing an example plugin while trying to fix the library to begin with.

    Yeah, looks like my code as well. I don't know why people are losing connection on Linux.

    I knew SQLite was included in craftbukkit.jar (org.sqlite), but where is MySQL? If it is built-in I wonder why one of my plugins uses "mysql.jar" and "mysql-connector-java-bin.jar".

    That's why I was asking Kanlaki101 what he meant when he started talking about connectors.

    Wait, what were you doing with the manifest file?

    As I told @Celtic Minstrel, I plan on adding functions like this once we fix more important problems such as keeping the connection persistent on Linux.

    Or if the built-in were coded with a higher level of abstraction (but then this library wouldn't exist now would it?).

    I've been meaning to ask @alta189 why he had all those exceptions as I could not ascertain why they were there in the first place. I removed them so hopefully we'll find out why.
  17. Offline

    Kanlaki101

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Was setting the file path to the jdbc connector.
    Like I said, I was following some very old and outdated guides.
  18. Offline

    Lolmewn BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    the version with the removed exceptions, has it been uploaded yet?
    Going to test when I get back home :p
  19. Offline

    PatPeter

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    What the hell...

    There was a message in my last post that notified everyone of 3.0.5's release, above my quote of HSAR and it's gone. It said something along the lines of:

    3.0.5 is out! (And probably broken!) Feel free to test and give feedback.

    Now I understand what you were trying to do Kanlaki101, lol.
  20. Offline

    Lolmewn BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Magic *poof* I guess.. :p
  21. Offline

    HSAR

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I've heard some people complain about disappearing posts as well...

    I forgot to reply to your question - SQL is something I'm working on right now, but I figured it would make more sense if I just messed around with some code.
  22. Offline

    SwearWord

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @PatPeter
    Sigh...since this isn't up on GitHub I couldn't send a pull request. For your getStatement method in DatabaseHandler you need to change all of it to .equalsIgnoreCase
  23. Offline

    alexh

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    i should test the new release i guess
    [edit] good news it still works my end...
    im adding http requests to my plugin so... ill send ya my code for that when im done :)

    This post has been edited 1 time. It was last edited by alexh Sep 20, 2011.
  24. Offline

    Mr Smith

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    for me everything is okay. Plugin works very well and don't lose connection.
    Thanks Peter :)
  25. Offline

    PatPeter

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Oh no, I did that on purpose to teach proper, capitalized SQL statements.

    Just kidding.

    ANOTHER MISSING POST! I replied to someone telling them that getStatement() was broken because it wasn't equalsIgnoreCase()... Regardless:

    Code:
    - 2011-09-13 03:01 - Fixed getStatement() by changing equals() to equalsIgnoreCase().
    I'll start adding some of the query-automation methods and building PreparedStatement into the normal methods when university settles down.

    This post has been edited 3 times. It was last edited by PatPeter Sep 23, 2011.
  26. Offline

    Lolmewn BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    The forum is making fun of you :p
    *Let's see.. Ah! PatPeter posted something! *delete*
  27. Offline

    PatPeter

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Silly @PatPeter, MySQL support is in Bukkit! *admin deletes post*
  28. Offline

    Lolmewn BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    hmm.. it seems it's true what ur saying cuz that post didn't get deleted.
    :O
  29. Offline

    alexh

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    If its ok with patpeter i might write the docs for this if i have time, i have about all day on saturdays to do what i want. im also planing or finishing my http request libary and sending that to patpeter for inclusion in this libary.

    But note im busy with college though the week so dont expect much quickley :)
    and patpeter is busy with uni so well see what happens :)
  30. Offline

    SwearWord

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Why would HTTP requests need a wrapper or belong here?

Share This Page