[INACTIVE] SQLite and MySQL Tutorial/Library

Discussion in 'Resources' started by alta189, May 12, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    fregaPT I steal plugins as my own

    Hey
    I am not able to download it :s
    Reason ?

    Hey
    I am getting a console error with your plugin
    I posted a thread with it in plugin development
    Here's the link: http://forums.bukkit.org/threads/he...rom-sql-tutorial-from-alta.17807/#post-308493

    Help!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 16, 2016
  2. Offline

    Piddu

    i was just looking for a db on file handler, thx Alta gonna use yours =)

    Advice for everybody, when declaring your folder path, instead of doing

    Code:
    String path = "plugins/PluginName";
    use this:

    Code:
    String path = "plugin" + File.separator + "pluginname";
    Using / or \ may cause problems...
     
  3. Offline

    alta189

    Thanks for the advice :D I will change that in the updated tutorial that shows the new features. I will be working on that tomorrow! :D
     
  4. Offline

    Tagette

    Why am I getting this error when I start up my plugin?

    Code:
    18:23:40 [SEVERE] java.lang.UnsatisfiedLinkError:
     /private/var/folders/P7/P72dGG2IG3WT-UlRsVYIoU+++TM/-Tmp-/sqlite-3.7.2-
    libsqlitejdbc.jnilib:  no suitable image found.  Did find:
     /private/var/folders/P7/P72dGG2IG3WT-UlRsVYIoU+++TM/-Tmp-/sqlite-3.7.2-
    libsqlitejdbc.jnilib: unknown required load command 0x80000022
    I have sqlite in my lib folder.
    "sqlitejdbc-v056.jar"
     
  5. Offline

    alta189

    I have no idea, my lib doesnt require it... source?
     
  6. Offline

    Tagette

    It probably isn't your lib actually, it says it for some other plugins too.
     
  7. Offline

    alta189

    Ok :D
     
  8. Offline

    Lolmewn

    Question! How do I update a row? I will use it for my Skillz plugin, which constantly has to update XP levels. A row looks like this:
    Code:
    String query = "CREATE  TABLE skillz (  'id' INTEGER PRIMARY KEY,  'player' VARCHAR(80) NOT NULL ,  " +
                            "'skill' TEXT NOT NULL ,  'xp' TEXT NOT NULL ,  'level' TEXT NOT NULL);";
     
  9. PHP:
    String updateQuery "UPDATE skillz SET xp='desiredvalue' WHERE xp='oldvalue' AND player='player' AND skill='skill';
     
    Lolmewn likes this.
  10. Offline

    Lolmewn

    Also, can I do something like this? :
    Code:
    String query = "SELECT id, player, skill, xp, level FROM skillz WHERE player = " + p +" AND skill = " + skill;
     
  11. Yeah sure, I just re-formatted your query because a few little things were wrong ;)
    PHP:
    String query "SELECT id, player, skill, xp, level FROM skillz WHERE player ='" "' AND skill = "' + skill';"
     
  12. Offline

    Lolmewn

    It's still wrong, but I found out I think :p
    (you have "', while it should be '" (if you can see the difference at all))
     
  13. Yeah, things like that are important though, Java doesn't bother to check sql syntax :p
     
  14. Offline

    Lolmewn

    Any Quick way to convert all my data from flatfite to SQL?
    Flatfile looks something like this (example is lolmewn.txt):
    Code:
    #[Skill]=[XP];[Level]
    #Tue May 24 17:22:55 CEST 2011
    acrobatics=7969;13
    unarmed=50;2
    swimming=2;1
    digging=2030;8
    axes=72;3
    mining=2079;8
    farming=0;0
    woodcutting=502;5
    archery=724;6
    swords=0;0
    
    The word is the skill, the int after that is the XP, and then comes the level. Any Quick way to let it import from ALL files in that same folder?
     
  15. I don't think it's that straightforward. You'd have to read each value and pass it into an array then insert those values into a new SQL table.
     
  16. Offline

    Lolmewn

    Tested, im getting this:
    Code:
    18:52:53 [SEVERE] [Skillz] SQLite exception on initialize java.sql.SQLException: [SQLITE_CANTOPEN]  Unable to open the database file (out of
     memory)
    18:52:53 [SEVERE] [Skillz] SQLite exception on initialize java.sql.SQLException: [SQLITE_CANTOPEN]  Unable to open the database file (out of
     memory)
    18:52:53 [SEVERE] Error occurred while enabling Skillz v1.62 (Is it up to date?): null
    java.lang.NullPointerException
            at nl.lolmen.sqllitelib.DatabaseHandler.checkTable(DatabaseHandler.java:144)
            at nl.lolmen.sqllitelib.sqlCore.checkTable(sqlCore.java:82)
            at nl.lolmen.Skillz.Skillz.onEnable(Skillz.java:70)
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:125)
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:750)
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:253)
            at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:132)
            at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:110)
            at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:218)
            at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:205)
            at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:145)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:265)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:394)
    I gave the server 4GB, and it says this. Is there something wrong in my code or something? My code is this:
    Code:
    if(useSql.equalsIgnoreCase("true")){
                dbManager = new sqlCore(this.log, this.logPrefix, "skillz", "plugins/Skillz");
                dbManager.initialize();
                if (!dbManager.checkTable("skillz")) {
                    String query = "CREATE  TABLE skillz (  'id' INTEGER PRIMARY KEY,  'player' VARCHAR(80) NOT NULL ,  " +
                            "'skill' TEXT NOT NULL ,  'xp' TEXT NOT NULL ,  'level' TEXT NOT NULL);";
                    dbManager.createTable(query);
                }
            }
    @Adamki11s I love you helping me :p
     
    Adamki11s likes this.
  17. Have you created the directory for the database?
     
  18. Offline

    Lolmewn

    You mean the dir "plugins/Skillz"? It already was created, in the video they said I should leave that trailing /.

    @Adamki11s So I don't know what i'm doing wrong, but I don't see a new .sql file get created or something.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 16, 2016
  19. @Lolmewn I'm not too sure but you should be initialising each database at 'onEnable' not just when creating.
    PHP:
    public void onEnable(){
        
    dbManager = new sqlCore(this.logthis.logPrefix"skillz""plugins/Skillz");
        
    dbManager.initialize();
    }
     
  20. Offline

    Lolmewn

  21. Offline

    alta189

    Can you send me the complete errors and your source?
     
  22. Offline

    Piddu

    Tried my plugin on a different machine running Linux and:
    22:40:43 [WARNING] [ParaFulmine]Error at SQL INSERT Query: java.sql.SQLException: [SQLITE_BUSY] The database file is locked (database is locked)

    i have never seen that error on my PC ( win XP ) and a friend tried it on his PC ( Linux ) without errors..
     
  23. Offline

    alta189

    Its an error that will be fixed in the update coming out tomorrow :D
     
  24. Offline

    Piddu

  25. Offline

    alta189

  26. Offline

    Lolmewn

    This is my onEnable:
    Code:
    public void onEnable() {
            if (!Settings.exists()) {
                makeSettings(Settings);
            }
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Normal, this);
            pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Priority.Normal, this);
            pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
            pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Priority.Normal, this);
            loadSettings();
            if(useSql.equalsIgnoreCase("true")){
                dbManager = new sqlCore(this.log, this.logPrefix, "skillz", "plugins/Skillz");
                dbManager.initialize();
                if (!dbManager.checkTable("skillz")) {
                    String query = "CREATE  TABLE skillz (  'id' INTEGER PRIMARY KEY,  'player' VARCHAR(80) NOT NULL ,  " +
                            "'skill' TEXT NOT NULL ,  'xp' TEXT NOT NULL ,  'level' TEXT NOT NULL);";
                    dbManager.createTable(query);
                }
            }
            
            new File(maindir).mkdir();
            new File(maindir+"users/").mkdir();
            new File(maindir+"Skillz/").mkdir();
            File dir = new File(maindir+ "Skillz/");
            File filename[] = dir.listFiles();        
            for (File f : filename){
                String fn = f.getName();
                log.info("Loaded file " + fn);
            }
            
            
            log.info("Skillz Enabled!");
        }
    And this is the error:
    Code:
    146 recipes
    16 achievements
    07:40:29 [INFO] Starting minecraft server version Beta 1.5_02
    07:40:29 [INFO] Loading properties
    07:40:29 [INFO] Starting Minecraft server on *:25564
    07:40:29 [WARNING] **** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!
    07:40:29 [WARNING] The server will make no attempt to authenticate usernames. Beware.
    07:40:29 [WARNING] While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect w
    ith any username they choose.
    07:40:29 [WARNING] To change this, set "online-mode" to "true" in the server.settings file.
    07:40:29 [INFO] This server is running Craftbukkit version git-Bukkit-0.0.0-753-g34e310c-b803jnks (MC: 1.5_02)
    07:40:29 [INFO] Preparing level "world"
    07:40:29 [INFO] Preparing start region
    07:40:30 [INFO] Loaded Essentials build 2.2.5 maintained by Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo and ceulemans.
    07:40:30 [INFO] GroupManager - INFO - Scheduled Data Saving is set for every 10 minutes!
    07:40:30 [INFO] GroupManager version 1.0(alpha-5) is enabled!
    07:40:30 [INFO] Fake Permissions version 2.5.1 is enabled!
    07:40:30 [INFO] [FastObby] v2.0 enabled!
    07:40:30 [INFO] [iConomy] Logging is currently disabled.
    07:40:31 [INFO] [iConomy] v5.0 (Eruanna) loaded.
    07:40:31 [INFO] [iConomy] Developed by: [Nijikokun]
    07:40:31 [INFO] [iConomy] hooked into Permissions.
    07:40:31 [INFO] [Repair] enabled!
    07:40:31 [SEVERE] [Skillz] SQLite exception on initialize java.sql.SQLException: [SQLITE_CANTOPEN]  Unable to open the database file (out of
     memory)
    07:40:31 [SEVERE] [Skillz] SQLite exception on initialize java.sql.SQLException: [SQLITE_CANTOPEN]  Unable to open the database file (out of
     memory)
    07:40:31 [SEVERE] Error occurred while enabling Skillz v1.62 (Is it up to date?): null
    java.lang.NullPointerException
            at nl.lolmen.sqllitelib.DatabaseHandler.checkTable(DatabaseHandler.java:144)
            at nl.lolmen.sqllitelib.sqlCore.checkTable(sqlCore.java:82)
            at nl.lolmen.Skillz.Skillz.onEnable(Skillz.java:71)
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:125)
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:750)
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:253)
            at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:132)
            at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:110)
            at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:218)
            at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:205)
            at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:145)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:265)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:394)
    07:40:31 [INFO] [Sortal] version 3.4 is enabled!
    07:40:31 [INFO] Done (0.138s)! For help, type "help" or "?"
     
  27. Offline

    alta189

    Very odd indeed, send me the source in a zip so that I can test it :D
     
  28. Offline

    Lolmewn

    Will do when I get home :p

    @alta189 here it is: http://dl.dropbox.com/u/7365249/src.zip

    @alta189 anything yet?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 16, 2016
  29. Offline

    alta189

    I just got home :D Will look at it soon.
     
  30. Offline

    Lolmewn

    Yaay :p
     
Thread Status:
Not open for further replies.

Share This Page