[INACTIVE] SQLite and MySQL Tutorial/Library

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

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

    alta189

    Updated :D
     
  2. Offline

    Lolmewn

    Thanx you!
     
  3. Offline

    alta189

    Its really different look the the example plugin :D
     
  4. Offline

    Lolmewn

    Njiegh!
    Code:
    19:05:09 [INFO] [Skillz] SQLite warming up...
    19:05:09 [SEVERE] [Skillz] SQLite exception on initialize java.sql.SQLException: [SQLITE_CANTOPEN]  Unable to open the database file (out of
     memory)
    19:05:09 [SEVERE] [Skillz] SQLite exception on initialize java.sql.SQLException: [SQLITE_CANTOPEN]  Unable to open the database file (out of
     memory)
    19:05:09 [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:166)
            at nl.lolmen.sqllitelib.sqlCore.checkTable(sqlCore.java:82)
            at nl.lolmen.Skillz.Skillz.onEnable(Skillz.java:73)
            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 org.bukkit.craftbukkit.CraftServer.reload(CraftServer.java:337)
            at org.bukkit.command.SimpleCommandMap$ReloadCommand.execute(SimpleCommandMap.java:243)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:127)
            at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:271)
            at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:401)
            at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:386)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:292)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:394)
    and
    Code:
    log.info(logPrefix + "SQLite warming up...");
    
    File pFolder = new File("plugins/Skillz");
                dbManager = new sqlCore(this.log, this.logPrefix, "skillz", pFolder.getPath());
                dbManager.initialize();
                if (dbManager.checkTable("skillz") == false) {
                    String query = "CREATE TABLE skillz ( 'id' INTEGER PRIMARY KEY , 'player' CARCHAR(80) NOT NULL , 'skill' TEXT NOT NULL , 'xp' INTEGER NOT NULL , 'level' INTEGER NOT NULL);";
                    dbManager.createTable(query);
                }
    Looked @ example plugin, and changed to:
    Code:
    if(useSql == true){
                log.info(logPrefix + "SQLite warming up...");
                dbManager = new sqlCore(this.log, this.logPrefix, "skillz", pFolder.getPath());
                dbManager.initialize();
                if (!dbManager.checkTable("skillz").booleanValue()) {
                    String query = "CREATE TABLE skillz (id INT AUTO_INCREMENT PRIMARY_KEY , player VARCHAR(255) NOT NULL , skill VARCHAR(255) NOT NULL , xp INT NOT NULL , level INT NOT NULL);";
                    dbManager.createTable(query);
                }
            }
    Still same error.

    @alta189 MySQL seems to connect fine, thnx :p
    Waiting for some YouTube on MySQL, that is easier to follow than the source of the Owner plugin :p

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

    alta189

    Redownload Owner.zip because settings file had errors :D

    Yah, I know. Will do though. I have been busy. Probably up tomorrow on that :(. I have SOOOO much work todo :D

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

    Lolmewn

    You got any clue why my SQLite isn't working? I needz it xD
     
  7. Offline

    alta189

    Thats a problem with your computer, you dont have enough memory.

    Allocate more memory to the server...

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

    Lolmewn

    This is my start.bat:
    Code:
    java -XX:PermSize=128m -XX:MaxPermSize=256m -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:ParallelGCThreads=3 -XX:MaxGCPauseMillis=5 -XX:+UseAdaptiveGCBoundary -XX:-UseGCOverheadLimit -XX:+UseBiasedLocking -XX:SurvivorRatio=8 -XX:TargetSurvivorRatio=90 -XX:MaxTenuringThreshold=15 -Xnoclassgc -XX:UseSSE=3 -XX:+UseLargePages -XX:+UseFastAccessorMethods -XX:+UseStringCache -XX:+UseCompressedStrings -XX:+OptimizeStringConcat -Xincgc -Xmx4G -Xms2G -jar craftbukkit-0.0.1-SNAPSHOT.jar
    I'm guessing 2G is more than enough for a server with only 6 plugins (essentials, Permissions and some of my own plugins in testing status). Still the same error.
     
  9. Offline

    alta189

    Try running it by its self

    Wait did some research on google: here is what it says :
    Code:
    Usually, SQLITE_CANTOPEN error means you can't open the database file,
    for example, the path is wrong, or you don't have correct permission
    (read/write) to open the file, etc.
    In addition, sqlite has to write xxx.journal file in the same folder
    with the database file, so
    you also need a write permission to the folder of your database files.
    The error message "out of memory" is observed when the program fails
    to find/open database files. Something strange about SQLite is it
    returns such a message even if it's not actually running out of the
    memory. 


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

    Lolmewn

    I changed it to:
    Code:
    @echo off
    java -Xmx4G -Xms4G -jar craftbukkit-0.0.1-SNAPSHOT.jar
    and removed every other plugin. Same error.. Can the problem maybe in my code?
    Code:
    dbManager = new sqlCore(this.log, this.logPrefix, "skillz", pFolder.getPath());             dbManager.initialize();             if (dbManager.checkTable("skillz") == false) {                 String query = "CREATE TABLE skillz ( 'id' INTEGER PRIMARY KEY , 'player' CARCHAR(80) NOT NULL , 'skill' TEXT NOT NULL , 'xp' INTEGER NOT NULL , 'level' INTEGER NOT NULL);";                 dbManager.createTable(query);             }
     
  11. Offline

    alta189

    Code looks fine, did you see this :
    [/CODE][/SIZE][/quote]
     
  12. Offline

    Tagette

    Mine doesn't give any errors but it also doesn't work lol. Ima keep looking.
     
  13. Offline

    Lolmewn

    Yes, I did see that. I have everything the same though as in the video. I will try and change it a little and see if it works then, but in the meanwhile: @Tagette, can you give me your code where it enables? Just to see if I am doing things right :p
     
  14. Offline

    Tagette

    Is this an appropriate way to check if a field exists? I've never used this before so I'm kinda iffy on using it.
    Code:
    
        public boolean checkField(String table, String column) {
            DatabaseMetaData dbm;
            boolean exists = false;
            try {
                dbm = connection.getMetaData();
                ResultSet columns = dbm.getColumns(null, null, table, column);
                while(columns.next()){
                    String columnName = columns.getString("COLUMN_NAME");
                    if(columnName.equals(column)){
                        exists = true;
                        break;
                    }
                }
            } catch (SQLException se) {
                core.writeError("Failed to check if column \"" + column + "\" exists: " + se.getMessage(), true);
                exists = false;
            }
            return exists;
        }
    EDIT: Added the variable 'column' in "dbm.getColumns" into one of the parameters. Found an example online and it seems that this would work fine.

    I have a different setup then his release but I'll try and get those parts together for you. :p

    Hm it seems that I have changed it a bit too much to the lib so I can only give you a little.
    Code:
    dbCore = new SQLCore(TLogger.getLog(), TLogger.getPrefix(),
        Template.name, plugin.getDataFolder().getPath() + "/Data");
    dbCore.initialize();
    
    Thats really not much lol.
    After that I create the table.

    EDIT: Oh TLogger.log is just the minecraft logger.
    EDIT: and Template.name is the name of my plugin.

    My problem is that my update is not working. This is the query I'm using. "UPDATE 'players' SET 'awesomeness' = '1' WHERE 'playername' = 'Tagette'"

    EDIT: Found it! Stupid me... It should not have single quote around table and field names... GRR

    SO: " UPDATE players SET awesomeness = '1' WHERE playername = 'Tagette' " is correct!

    *FIX*
    In your databaseHandler I found that your updateQuery function is using 'statement.executeQuery'. It should be using 'statement.executeUpdate', and I also changed that in the insertQuery function. Havn't looked at the insert though, however it works fine for me.

    EDIT: The deleteQuery also uses 'statement.executeQuery', I changed that as well. The 'statement.executeQuery' returns a ResultSet so the Update, Insert, and Delete don't use that one.

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

    Lolmewn

    Thnx for the replies, i will check it out when i get behind my pc
     
  16. Offline

    alta189

    already knew that, I had sent you a message saying the version I sent you had that error.
     
  17. Offline

    Tagette

    alright =P

    EDIT: You didn't say that specific error, just that you had errors.
     
  18. Offline

    Lolmewn

    Ok, I found out the problem. Appearently, the handler doesn't like a new database in the main plugin folder or something. I got errors when trying to create one in plugins/Skillz, but not in plugins/Skillz + "/data"
    Which is weird. Also, this is correct right?:
    Code:
    String query;
                query = "SELECT id, player, skill, xp, level FROM skillz WHERE player = " + p;
                ResultSet res = db.sqlQuery(query);
    Because it gives me errors.
     
  19. Offline

    Tagette

    The "/data" works fine for me. It shouldn't give an error when in 'plugins/Skillz' though.
    Try this:
    Code:
    query = "SELECT id, player, skill, xp, level FROM skillz WHERE player = '" + p + "'";
     
  20. Offline

    alta189

    Code:
    String query;
                query = "SELECT * FROM skillz WHERE player = '" + p.toString() + "';";
                ResultSet res = db.sqlQuery(query);
    And if


    Close but not perfect :D

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

    Lolmewn

    This is weird..
    Code:
    String query;
    String p = event.getPlayer().getName().toString();
    query = "SELECT * FROM skillz WHERE player = '" + p + "'";
                ResultSet res = db.sqlQuery(query);
                if(res == null){
    and I get this:
    Code:
    java.lang.NullPointerException
            at nl.lolmen.Skillz.SkillzPlayerListener.onPlayerJoin(SkillzPlayerListener.java:54)
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:243)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:58)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:310)
            at net.minecraft.server.ServerConfigurationManager.c(ServerConfigurationManager.java:117)
            at net.minecraft.server.NetLoginHandler.b(NetLoginHandler.java:96)
            at net.minecraft.server.NetLoginHandler.a(NetLoginHandler.java:74)
            at net.minecraft.server.Packet1Login.a(SourceFile:43)
            at net.minecraft.server.NetworkManager.b(NetworkManager.java:215)
            at net.minecraft.server.NetLoginHandler.a(NetLoginHandler.java:40)
            at net.minecraft.server.NetworkListenThread.a(SourceFile:91)
            at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:396)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:308)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:422)
    I want to use this to insert some data only once, when there is no data of that player found yet.
     
  22. Offline

    alta189

    Send me your source again
     
  23. Offline

    Lolmewn

    Will do tomorrow, in bed now xD
     
  24. Offline

    alta189

    OK, we will figure out this issue :D
     
  25. Offline

    Jayjay110

    OH poo I just finished my plugin, everything works fine for sql but it wont create the mysql database or table? help:

    2011-05-29 16:53:54 [SEVERE] Error occurred while enabling MysteryBox v1.0 (Is it up to date?): null
    java.lang.NullPointerException
    at com.alta189.sqlLibrary.MySQL.DatabaseHandler.checkTable(DatabaseHandler.java:134)
    at com.alta189.sqlLibrary.MySQL.mysqlCore.checkTable(mysqlCore.java:72)
    at com.servegame.n1p.MysteryBox.MysteryBox.loadMySQL(MysteryBox.java:399)
    at com.servegame.n1p.MysteryBox.MysteryBox.onEnable(MysteryBox.java:66)
    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 org.bukkit.craftbukkit.CraftServer.reload(CraftServer.java:337)
    at org.bukkit.command.SimpleCommandMap$ReloadCommand.execute(SimpleCommandMap.java:243)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:127)
    at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:271)
    at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:401)
    at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:386)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:292)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:394)



    At line 399

    if (this.manageMySQL.checkTable("blocks")){

    help :(
     
  26. Offline

    Lolmewn

    This works fine, the SQL Is starting and stuff:
    Code:
    if(useSql == true && useMySQL == false){
                log.info(logPrefix + "SQLite warming up...");
                new File(maindir + "data").mkdir();
                dbManager = new sqlCore(this.log, this.logPrefix, "skillz", "plugins/Skillz/data");
                dbManager.initialize();
                if (dbManager.checkTable("skillz").booleanValue() == false) {
                    String query = "CREATE TABLE skillz (id int, player TEXT, skill TEXT, xp int, level int);";
                    dbManager.createTable(query);
                }
            }
    But then we have this:
    Code:
    public void onPlayerJoin(PlayerJoinEvent event){
            String p = event.getPlayer().getName().toString();
            }else if(useSql == true && useMySQL == false){
                String query;
                query = "SELECT * FROM skillz WHERE player = '" + p + "'";
                ResultSet res = db.sqlQuery(query);
                if(res == null){
                    //There is no field for the player yet.
                    query = "INSERT INTO skillz (player, skill, xp, level) values (" + p + ", acrobatics , 0 , 0";
                    db.sqlQuery(query);
                    query = "INSERT INTO skillz (player, skill, xp, level) values (" + p + ", archery , 0 , 0";
                    db.sqlQuery(query);
                    query = "INSERT INTO skillz (player, skill, xp, level) values (" + p + ", digging , 0 , 0";
                    db.sqlQuery(query);
                    query = "INSERT INTO skillz (player, skill, xp, level) values (" + p + ", swords , 0 , 0";
                    db.sqlQuery(query);
                    query = "INSERT INTO skillz (player, skill, xp, level) values (" + p + ", woodcutting , 0 , 0";
                    db.sqlQuery(query);
                    query = "INSERT INTO skillz (player, skill, xp, level) values (" + p + ", unarmed , 0 , 0";
                    db.sqlQuery(query);
                    query = "INSERT INTO skillz (player, skill, xp, level) values (" + p + ", axes , 0 , 0";
                    db.sqlQuery(query);
                    query = "INSERT INTO skillz (player, skill, xp, level) values (" + p + ", swimming , 0 , 0";
                    db.sqlQuery(query);
                    query = "INSERT INTO skillz (player, skill, xp, level) values (" + p + ", farming , 0 , 0";
                    db.sqlQuery(query);
                    query = "INSERT INTO skillz (player, skill, xp, level) values (" + p + ", archery , 0 , 0";
                    db.sqlQuery(query);
                    query = "INSERT INTO skillz (player, skill, xp, level) values (" + p + ", mining , 0 , 0";
                    db.sqlQuery(query);
                    Skillz.log.info("Skillz SQL Entry created for " + p  + "!");
                    
                }
    
     
  27. Offline

    Tagette

    Hate to ask this but did you initialize the variable?

    Code:
    manageMySQL = new mysqlCore(log, logPrefix, host, database, username, password);
    manageMySQL.initialize();
    It seems your missing something in each of the querys.

    This:
    query = "INSERT INTO skillz (player, skill, xp, level) values (" + p + ", mining , 0 , 0";

    Should be:
    query = "INSERT INTO skillz (player, skill, xp, level) values (" + p + ", mining , 0 , 0)";

    *note the missing parentheses at the end*

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

    Jayjay110

    yeah I did lol
     
  29. Offline

    Lolmewn

    oh lol, forgot a ). Should I add a ; in there aswell?
     
  30. Offline

    Jayjay110

    can you see anything wrong wit mine?
     
Thread Status:
Not open for further replies.

Share This Page