Sqlite

Discussion in 'Plugin Development' started by sharp237, Oct 6, 2012.

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

    sharp237

    With Sqlite on my plugin it works fine, but once /stop and restart the server it gives this error:

    sqlite please close your previous result set

    I then have to delete my data.db folder and start it again. Then it works fine with no errors, until i restart.

    here is my code:

    Code:JAVA
    1.  
    2. package me.sharp237.thisserverplugin;
    3.  
    4. import java.lang.reflect.Field;
    5. import java.sql.ResultSet;
    6. import java.sql.SQLException;
    7. import java.util.logging.Logger;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.player.PlayerJoinEvent;
    11. import org.bukkit.plugin.PluginDescriptionFile;
    12. import org.bukkit.plugin.PluginManager;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14. import lib.PatPeter.SQLibrary.*;
    15.  
    16. public class ThisServerPlugin extends JavaPlugin implements Listener{
    17. public final Logger logger = Logger.getLogger("Minecraft");
    18. public final ThisServerPluginListener PlayerListener = new ThisServerPluginListener(this);
    19. public final MagicWand WandListener = new MagicWand(this);
    20.  
    21. public void onDisable() {
    22. PluginDescriptionFile pdfFile = getDescription();
    23. try
    24. {
    25. ThisServerPlugin.r.close();
    26. }
    27. catch(SQLException e100)
    28. {
    29. e100.printStackTrace();
    30. }
    31. mysql.close();
    32. this.logger.info(pdfFile.getName() + " Has Been Disabled");
    33. }
    34.  
    35. public void onEnable() {
    36. PluginDescriptionFile pdfFile = getDescription();
    37. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has Been Enabled");
    38. sqlConnection();
    39. sqlExist();
    40. PluginManager snow = getServer().getPluginManager();
    41. snow.registerEvents(this.PlayerListener, this);
    42. snow.registerEvents(this.WandListener, this);
    43. try
    44. {
    45. Field f = net.minecraft.server.Item.class.getDeclaredField("maxStackSize");
    46. f.setAccessible(true);
    47. f.setInt(net.minecraft.server.Item.APPLE, 5);
    48. f.setAccessible(false);
    49. }
    50. catch(Exception e)
    51. {
    52. e.printStackTrace();
    53. return;
    54. }
    55. }
    56. public void sqlConnection()
    57. {
    58. mysql = new SQLite(logger, "ThisServerPlugin", "Data", getDataFolder().getAbsolutePath());
    59. try
    60. {
    61. mysql.open();
    62. }
    63. catch(Exception e)
    64. {
    65. logger.info(e.getMessage());
    66. getPluginLoader().disablePlugin(this);
    67. }
    68. try
    69. {
    70. if(ThisServerPlugin.r != null)
    71. ThisServerPlugin.r.close();
    72. }
    73. catch(SQLException e101)
    74. {
    75. e101.printStackTrace();
    76. }
    77. }
    78. public void sqlExist()
    79. {
    80. if(!mysql.checkTable("players"))
    81. mysql.createTable("CREATE TABLE players (id INT PRIMARY KEY, playername STRING, extrainventoryslots INT, currentspell STRING, currentblazerodspell STRING);");
    82. if(!mysql.checkTable("spells"))
    83. mysql.createTable("CREATE TABLE spells (id INT PRIMARY KEY, playername STRING, ghasttear INT, fermentedspidereye INT, blazepowder INT, magmacream INT, speckledmelon INT, sulphur INT, brick INT, clayball INT, glowstonedust INT, inksack INT, slimeball INT, spidereye INT, netherwarts INT, sugar INT, redrose INT, yellowflower INT);");
    84. System.out.println("ThisServerPlugin Database Loaded.");
    85. }
    86.  
    87. public void addPlayer(PlayerJoinEvent event){
    88. Player player = event.getPlayer();
    89. r = mysql.query((new StringBuilder("SELECT * FROM players WHERE playername='")).append(player.getName()).append("';").toString());
    90. try {
    91. if(!r.next()){
    92. r.close();
    93. r = mysql.query((new StringBuilder("INSERT INTO players (playername,extrainventoryslots,currentspell,currentblazerodspell) VALUES ('")).append(player.getName()).append("',1,'nospell','nospell');").toString());
    94. r.close();
    95. }else{
    96. r.close();
    97. }
    98. }
    99. catch(SQLException e1)
    100. {
    101. e1.printStackTrace();
    102. }
    103. r = mysql.query((new StringBuilder("SELECT * FROM spells WHERE playername='")).append(player.getName()).append("';").toString());
    104. try {
    105. if(!r.next()){
    106. r.close();
    107. r = mysql.query((new StringBuilder("INSERT INTO spells (playername,ghasttear,fermentedspidereye,blazepowder,magmacream,speckledmelon,sulphur,brick,clayball,glowstonedust,inksack,slimeball,spidereye,netherwarts,sugar,redrose,yellowflower) VALUES ('")).append(player.getName()).append("',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);").toString());
    108. r.close();
    109. }else{
    110. r.close();
    111. }
    112. }
    113. catch(SQLException e2)
    114. {
    115. e2.printStackTrace();
    116. }
    117. }
    118.  
    119. public static SQLite mysql;
    120. static ResultSet r;
    121. public static ThisServerPlugin plugin;
    122. }
    123.  
     
  2. Offline

    bob7

    Please repost this using CODE, it's extremely illegible.. I think i see your problem, just repost so i can make sure :p
     
  3. Offline

    sharp237

    -=- bump -=-
     
  4. Offline

    bob7

    Here is what i THINK ur prob is..
    It's better to use public SQLite mysql; at the top.. And why is it a static?
     
  5. Offline

    sharp237

    If i remove the 'static' then the plugin doesn't work even before I restart the server.
     
  6. Offline

    Sleaker

    that usually indicates another issue. I'd see what it's erroring on when you remove the static modifier and go from there.
     
  7. Offline

    hockeygoalie5

    Make a new ResultSet for every query you execute, and close it as soon as you don't need it anymore. Open the Connection and ready the Statement on OnEnable, and then close both on OnDisable. Here's my code:
    Code:
     
    Connection conn;
    static Statement stat;
     
     
    ...
     
    public void onEnable() {
     
        try {
            conn = DriverManager.getConnection("jdbc:sqlite:plugins/...");
            stat = conn.createStatement();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
     
    ...
     
    public void onDisable() {
        try {
            conn.close();
            stat.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
     
    
     
  8. Offline

    sharp237

    Sleaker & hockeygoalie5
    If I remove the static then it gives me a NullPointerException for every line that has 'mysql' in after creating the table. For example, in my code above the 1st line to give this error is line 89.
     
  9. Offline

    Sleaker

    This means you're not accessing a valid object, or it is null when you do try to access it.
     
  10. Offline

    sharp237

    Err, well doesn't NullPointerException mean its null? I don't really know :/ Also, wouldn't 'mysql' be valid because it works when I use static?

    -=- bump -=-

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

    hockeygoalie5

    Set up your SQLite connections the way I did it in my post, then when you execute a query, use something similar to this:
    Code:
    try {
        ResultSet rs = stat.executeQuery("query");
        // Do stuff with rs
        rs.close();
    } catch ...
    
    Also remember to only create a ResultSet if you want the query to return something (like a SELECT query). If you only want to change something (e.g., insert a row), use this:
    Code:
    try {
        stat.execute("query");
    }
    
     
  12. Offline

    sharp237

    :( Sqlite isn't working out for me... I might just use a hashmap for every column.
     
  13. Offline

    PatPeter

    This either took me 5 minutes or 30 minutes to fix. I can't tell since I got distracted and started making my library a whole lot better.

    Code:
    package me.sharp237.thisserverplugin;
     
    import java.lang.reflect.Field;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.logging.Logger;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import lib.PatPeter.SQLibrary.*;
     
    public class ThisServerPlugin extends JavaPlugin { // Not needed: implements Listener
        public final Logger logger = Logger.getLogger("Minecraft");
        public final ThisServerPluginListener PlayerListener = new ThisServerPluginListener(this);
        public final MagicWand WandListener = new MagicWand(this);
        public final String PREFIX = "ThisServerPlugin ";
     
        // ALWAYS PUT YOUR FIELDS TOGETHER, NEVER AT THE BOTTOM OF A FILE
        public static Database sql; // Why did you call an SQLite variable sql? Also always use interface names to save implementations
        //static ResultSet r; // Create your ResultSets in your functions, no reason to make it a field
        //public static ThisServerPlugin plugin; // Use 'this', you already did it above for the PluginListener
     
        public void onEnable() {
            PluginDescriptionFile pdfFile = getDescription();
            this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has Been Enabled");
            sqlConnection();
            sqlExist();
         
            PluginManager snow = getServer().getPluginManager();
            snow.registerEvents(this.PlayerListener, this);
            snow.registerEvents(this.WandListener, this);
         
            try {
                // DO NOT USE REFLECTION IF YOU DO NOT HAVE TO
                Field f = net.minecraft.server.Item.class.getDeclaredField("maxStackSize");
                f.setAccessible(true);
                f.setInt(net.minecraft.server.Item.APPLE, 5);
                f.setAccessible(false);
            } catch (NoSuchFieldException e) { // Always use specific exceptions
                e.printStackTrace(); // And you should never print stack traces.
                return;
            } catch (SecurityException e) {
                e.printStackTrace();
                return;
            }
        }
     
        public void onDisable() {
            PluginDescriptionFile pdfFile = getDescription();
            try {
                sql.close();
                //ThisServerPlugin.r.close(); // You close r in your sqlConnection(), this is probably where your NullPointerException is coming from
            } catch(SQLException e100) {
                e100.printStackTrace();
            }
            sql.close();
            this.logger.info(pdfFile.getName() + " Has Been Disabled");
        }
     
        public void sqlConnection() {
            sql = new SQLite(logger, PREFIX, "Data", getDataFolder().getAbsolutePath());
            try {
                sql.open();
            } catch(Exception e) {
                logger.info(e.getMessage());
                getPluginLoader().disablePlugin(this);
            }
            try {
                if(ThisServerPlugin.r != null)
                ThisServerPlugin.r.close();
            } catch(SQLException e101) {
                e101.printStackTrace();
            }
        }
     
        public void sqlExist() {
            // Use query() for now, createTable is going to be deprecated soon and I'm not sure if it works currently
            if(!sql.checkTable("players"))
                sql.query("CREATE TABLE players (id INT PRIMARY KEY, playername STRING, extrainventoryslots INT, currentspell STRING, currentblazerodspell STRING);");
            if(!sql.checkTable("spells"))
                sql.query("CREATE TABLE spells (id INT PRIMARY KEY, playername STRING, ghasttear INT, fermentedspidereye INT, blazepowder INT, magmacream INT, speckledmelon INT, sulphur INT, brick INT, clayball INT, glowstonedust INT, inksack INT, slimeball INT, spidereye INT, netherwarts INT, sugar INT, redrose INT, yellowflower INT);");
            System.out.println(PREFIX + "Database Loaded.");
        }
     
        public void addPlayer(PlayerJoinEvent event){
            Player player = event.getPlayer();
            ResultSet r;
            ResultSet s;
            PreparedStatement ps;
         
            // Don't use StringBuilder, use PreparedStatements. If you have to use toString() to get a query, you're doing it wrong
            // Also, don't use semicolons. The driver does it automatically and for some functions specifying it will break your query
            //r = sql.query((new StringBuilder("SELECT * FROM players WHERE playername='")).append(player.getName()).append("';").toString());
            ps = sql.prepare("SELECT * FROM players WHERE playername=?");
            ps.setString(1, player.getName());
            // In the future, you will be able to do this, uncomment this line next version
            // r = sql.query(ps);
            r = ps.executeQuery();
         
            try {
                if (!r.next()){
                    // Do the same as above
                    //s = sql.query((new StringBuilder("INSERT INTO players (playername,extrainventoryslots,currentspell,currentblazerodspell) VALUES ('")).append(player.getName()).append("',1,'nospell','nospell');").toString());
                    ps = sql.prepare("INSERT INTO players (playername,extrainventoryslots,currentspell,currentblazerodspell) VALUES (?, 1, 'nospell', 'nospell')");
                    ps.setString(1, player.getName());
                    // In the future, you will be able to do this, uncomment this line next version
                    // r = sql.query(ps);
                    r = ps.executeQuery();
                    s.close();
                } else {
                    r.close();
                    s.close();
                }
            } catch(SQLException e1) {
                e1.printStackTrace();
            }
         
            r = sql.query((new StringBuilder("SELECT * FROM spells WHERE playername='")).append(player.getName()).append("';").toString());
            try {
                if(!r.next()){
                    //s = sql.query((new StringBuilder("INSERT INTO spells (playername,ghasttear,fermentedspidereye,blazepowder,magmacream,speckledmelon,sulphur,brick,clayball,glowstonedust,inksack,slimeball,spidereye,netherwarts,sugar,redrose,yellowflower) VALUES ('")).append(player.getName()).append("',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);").toString());
                    ps = sql.prepare("INSERT INTO spells (playername,ghasttear,fermentedspidereye,blazepowder,magmacream,speckledmelon,sulphur,brick,clayball,glowstonedust,inksack,slimeball,spidereye,netherwarts,sugar,redrose,yellowflower) VALUES (?, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);");
                    ps.setString(1, player.getName());
                    // In the future, you will be able to do this, uncomment this line next version
                    // r = sql.query(ps);
                    r = ps.executeQuery();
                    s.close();
                } else {
                    r.close();
                    s.close();
                }
            } catch(SQLException e2) {
                e2.printStackTrace();
            }
         
        }
    }
    The Java syntax on this forum is so broken and has disgusting colors. I don't know why it exists. Also, when you copy from it it does not retain indentation, which is just so annoying. I had to go through this code and reindent all of it.

    No, always save implementations to their interface.

    ... and why should a variable named mysql be saved to a class called SQLite?

    You're using this on your listeners, so it should work. Whether it's static or non-static doesn't matter. It should work either way. However, if it does not work one way you might not be extending the plugin the right way.

    Yes, please listen to this man.

    Well at least try to make use of the library he's using (my library). :p

    No, that's a terrible, terrible idea.

    Unless you don't need persistent storage.

    If errors continue after the fixes that I've suggested, check that the SQLite database file exists beforehand, even though you shouldn't have to.
     
  14. Offline

    Sushi

    Does your library support PreparedStatements (for better security and speed)?
     
  15. Offline

    sharp237

    Because you have to close a query if it returns something like (SELECT) before opening another query which uses SELECT, how can I use information from 2 different queries at once?
     
  16. Offline

    hockeygoalie5

    Use two ResultSets:
    Code:
    try {
        ResultSet rs = stat.executeQuery("...");
        ResultSet rs2 = stat.executeQuery("...");
        rs.close()
        rs2.close()
    } catch(SQLException e) {
        e.printStackTrace();
    }
    
     
  17. Offline

    sharp237

    PatPeter I'm having trouble updating the table. When I do:

    try{
    ResultSet rs = plugin.sqlite.query("SELECT * FROM spells WHERE playername='" + player + "'");
    plugin.sqlite.query("UPDATE spells SET ghasttear=1 WHERE playername='sharp237'");
    rs.close();
    }
    catch(Exception e)
    {
    plugin.logger.info("Unable to Sqlite");
    }

    It tells me in the console that I need to close my previous result set. And if i do this:

    try{
    ResultSet rs = plugin.sqlite.query("SELECT * FROM spells WHERE playername='" + player + "'");
    rs.updateInt(3,1);
    rs.close();

    }
    catch(Exception e)
    {
    plugin.logger.info("Unable to Sqlite");
    }

    It does tells me in the console:

    Unable to Sqlite
     
  18. Offline

    Sushi

    I think you need to learn Java.

    You can try printing the stacktrace in the exception to see the issue though.
     
  19. Offline

    sharp237

    It gives me this error:

    Code:
    17:12:47 [INFO] Unable to log to Sqlite DB!
    17:12:47 [SEVERE] java.sql.SQLException: not implemented by SQLite JDBC driver
    17:12:47 [SEVERE]      at org.sqlite.Unused.unused(Unused.java:29)
    17:12:47 [SEVERE]      at org.sqlite.Unused.updateInt(Unused.java:202)
    17:12:47 [SEVERE]      at me.sharp237.thisserverplugin.MagicWand.changeWandCont
    ents(MagicWand.java:114)
    17:12:47 [SEVERE]      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native M
    ethod)
    17:12:47 [SEVERE]      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown S
    ource)
    17:12:47 [SEVERE]      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unkno
    wn Source)
    17:12:47 [SEVERE]      at java.lang.reflect.Method.invoke(Unknown Source)
    17:12:47 [SEVERE]      at org.bukkit.plugin.java.JavaPluginLoader$1.execute(Jav
    aPluginLoader.java:330)
    17:12:47 [SEVERE]      at org.bukkit.plugin.RegisteredListener.callEvent(Regist
    eredListener.java:62)
    17:12:47 [SEVERE]      at org.bukkit.plugin.SimplePluginManager.fireEvent(Simpl
    ePluginManager.java:477)
    17:12:47 [SEVERE]      at org.bukkit.plugin.SimplePluginManager.callEvent(Simpl
    ePluginManager.java:462)
    17:12:47 [SEVERE]      at net.minecraft.server.NetServerHandler.a(NetServerHand
    ler.java:1109)
    17:12:47 [SEVERE]      at net.minecraft.server.Packet102WindowClick.handle(Sour
    ceFile:29)
    17:12:47 [SEVERE]      at net.minecraft.server.NetworkManager.b(NetworkManager.
    java:276)
    17:12:47 [SEVERE]      at net.minecraft.server.NetServerHandler.d(NetServerHand
    ler.java:109)
    17:12:47 [SEVERE]      at net.minecraft.server.ServerConnection.b(SourceFile:35
    )
    17:12:47 [SEVERE]      at net.minecraft.server.DedicatedServerConnection.b(Sour
    ceFile:30)
    17:12:47 [SEVERE]      at net.minecraft.server.MinecraftServer.q(MinecraftServe
    r.java:581)
    17:12:47 [SEVERE]      at net.minecraft.server.DedicatedServer.q(DedicatedServe
    r.java:212)
    17:12:47 [SEVERE]      at net.minecraft.server.MinecraftServer.p(MinecraftServe
    r.java:474)
    17:12:47 [SEVERE]      at net.minecraft.server.MinecraftServer.run(MinecraftSer
    ver.java:406)
    17:12:47 [SEVERE]      at net.minecraft.server.ThreadServerApplication.run(Sour
    ceFile:539)
    17:12:49 [INFO] 2
    >
     
  20. Offline

    Sushi

    You're trying to use a JDBC method that doesn't exist for SQLite.
     
  21. Offline

    PatPeter

    Why yes it does! In the current version, however, support for them is small. As I posted above, in the next version you'll be able to do query(PreparedStatement ps). Right now you can only use prepare(String query) that returns a PreparedStatement and then leaves you to modify it from there. In addition, I'm adding query builders that will make use of PreparedStatements.

    What I do is create a class with the same structure as the table, initialize a new object, and set all the column data to that object's fields. What do you mean it returns something like (SELECT)?

    To my knowledge, you can't use two ResultSets at the same time with SQLite. I could be wrong though; I've never used SQLite in practice, only MySQL.

    As Sushi said, you can't use updateInt(). Use the UPDATE SQL statement. Also think of using PreparedStatements:

    Code:
    try{
        PreparedStatement ps = plugin.sql.prepare("SELECT * FROM spells WHERE playername=?");
        ps.setString(1, player);
        //plugin.sql.query(ps); // In the next version of the library.
        ResultSet rs = ps.executeQuery();
    } catch (SQLException e) {
        plugin.logger.warning("Could not execute query.");
    }
     
  22. rtry wrapping al resultsets into try-whit-resources blocks
     
  23. Offline

    sharp237

    I made another small plugin specifically to try and get sqlite to work. Here is the code:

    Code:
    package me.sharp237.testplugin;
     
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.util.logging.Logger;
     
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import lib.PatPeter.SQLibrary.SQLite;
     
    public class TestPlugin extends JavaPlugin implements Listener{
        public final Logger logger = Logger.getLogger("Minecraft");
        public TestPlugin plugin;
        public SQLite sqlite;
        public TestPlugin(){
        }
     
        public void onEnable() {
            PluginDescriptionFile pdfFile = getDescription();
            this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has Been Enabled");
            PluginManager reg = getServer().getPluginManager();
            reg.registerEvents(this, this);
            sqlConnection();
            sqlTableCheck();
        }
     
        public void onDisable() {
            PluginDescriptionFile pdfFile = getDescription();
            this.logger.info(pdfFile.getName() + " Has Been Disabled");
            sqlite.close();
        }
        public void sqlConnection()
        {
            sqlite = new SQLite(getLogger(), "TestPlugin", "DataDB", getDataFolder().getAbsolutePath());
            try
            {
                sqlite.open();
            }
            catch(Exception e)
            {
                getLogger().info(e.getMessage());
                getPluginLoader().disablePlugin(this);
            }
        }
     
        public void sqlTableCheck()
        {
            if(sqlite.checkTable("players"))
            {
                return;
            } else
            {
                sqlite.query("CREATE TABLE IF NOT EXISTS `players` ('playername' STRING NOT NULL, 'number' INT NOT NULL)");
                getLogger().info("players has been created");
                return;
            }
        }
     
        @EventHandler
        public void onJoin(PlayerJoinEvent event){
            Player player = event.getPlayer();
            try {
            ResultSet rs = sqlite.query((new StringBuilder("SELECT * FROM players WHERE playername='")).append(player.getName()).append("'").toString());
                if(!rs.next()){
                        sqlite.query((new StringBuilder("INSERT INTO players VALUES ('")).append(player.getName()).append("', 0)").toString());
                        rs.close();
                } else
                {
                    rs.close();
                    return;
                }
            }
            catch(Exception e)
            {
                this.logger.info("Unable to log to Sqlite DB!");
            }
            player.sendMessage("Added to table!");
        }
     
        @EventHandler
        public void onRightClick(PlayerInteractEvent event){
            this.logger.info("leftclick block");
            if(event.getAction().equals(Action.LEFT_CLICK_BLOCK)){
                Player player = event.getPlayer();
                String name = player.getName();
                try{
                    PreparedStatement ps = sqlite.prepare("SELECT * FROM players WHERE playername='" + name + "'");
                    //plugin.sql.query(ps); // In the next version of the library.
                    ResultSet rs = ps.executeQuery();
                    int currentNumber =  rs.getInt("number");
                    player.sendMessage("CurrentNumber = " + currentNumber);
                    int newNumber = currentNumber + 1;
                    player.sendMessage("newNumber = " + newNumber);
                    rs.close();
                    ps.close();
                    sqlite.query("UPDATE players SET 'number'=" + newNumber + " WHERE playername='" + name + "'");
                    player.sendMessage("Updated");
                    rs.close();
                }
                    catch(Exception e)
                    {
                    this.logger.info("Unable to log to Sqlite DB!");
                    e.printStackTrace();
                    }
            }
        }
    }
    It all works fine, until I reload or restart. Then it will give this error:

    Code:
    208 recipes
    27 achievements
    12:25:02 [INFO] Starting minecraft server version 1.4.2
    12:25:02 [INFO] Loading properties
    12:25:02 [INFO] Default game type: SURVIVAL
    12:25:02 [INFO] Generating keypair
    12:25:03 [INFO] Starting Minecraft server on *:25565
    12:25:04 [INFO] This server is running CraftBukkit version git-Bukkit-1.3.2-R3.0
    -29-gc877eaa-b2437jnks (MC: 1.4.2) (Implementing API version 1.4.2-R0.1-SNAPSHOT
    )
    12:25:04 [INFO] [FortuneControl] Loading FortuneControl v1.0
    12:25:04 [INFO] [TestPlugin] Loading TestPlugin v1.0
    12:25:04 [INFO] [SQLibrary] Loading SQLibrary v3.1
    12:25:04 [INFO] Preparing level "world"
    12:25:05 [INFO] ----- Bukkit Auto Updater -----
    12:25:05 [INFO] It appears that you're running a Development Build, when you've
    specified in bukkit.yml that you prefer to run Recommended Builds.
    12:25:05 [INFO] If you would like to be kept informed about new Development Buil
    d releases, it is recommended that you change 'preferred-channel' in your bukkit
    .yml to 'dev'.
    12:25:05 [INFO] With that set, you will be told whenever a new version is availa
    ble for download, so that you can always keep up to date and secure with the lat
    est fixes.
    12:25:05 [INFO] If you would like to disable this warning, simply set 'suggest-c
    hannels' to false in bukkit.yml.
    12:25:05 [INFO] ----- ------------------- -----
    12:25:05 [INFO] Preparing start region for level 0 (Seed: 6607936131849442398)
    12:25:06 [INFO] Preparing spawn area: 52%
    12:25:06 [INFO] Preparing start region for level 1 (Seed: 6607936131849442398)
    12:25:07 [INFO] Preparing spawn area: 52%
    12:25:08 [INFO] Preparing spawn area: 97%
    12:25:08 [INFO] Preparing start region for level 2 (Seed: 6607936131849442398)
    12:25:08 [INFO] [FortuneControl] Enabling FortuneControl v1.0
    12:25:08 [INFO] FortuneControl Version 1.0 Has Been Enabled
    12:25:08 [INFO] [TestPlugin] Enabling TestPlugin v1.0
    12:25:08 [INFO] TestPlugin Version 1.0 Has Been Enabled
    12:25:09 [INFO] [SQLibrary] Enabling SQLibrary v3.1
    12:25:09 [INFO] SQLibrary loaded.
    12:25:09 [INFO] Server permissions file permissions.yml is empty, ignoring it
    12:25:09 [INFO] Done (4.531s)! For help, type "help" or "?"
    12:25:12 [INFO] sharp237[/127.0.0.1:56520] logged in with entity id 303 at ([wor
    ld] -238.22272128910214, 75.0, 249.8645928236756)
    12:25:17 [INFO] leftclick block
    12:25:23 [WARNING] [TestPlugin] TestPlugin[SQLite] Please close your previous Re
    sultSet to run the query:
            UPDATE players SET 'number'=6 WHERE playername='sharp237'
    12:25:23 [INFO] leftclick block
    12:25:26 [WARNING] [TestPlugin] TestPlugin[SQLite] Please close your previous Re
    sultSet to run the query:
            UPDATE players SET 'number'=7 WHERE playername='sharp237'
    12:25:26 [WARNING] Can't keep up! Did the system time change, or is the server o
    verloaded?
    12:25:41 [INFO] leftclick block
    12:25:41 [INFO] Unable to log to Sqlite DB!
    12:25:41 [SEVERE] java.sql.SQLException: [SQLITE_BUSY]  The database file is loc
    ked (database is locked)
    12:25:41 [SEVERE]      at org.sqlite.DB.newSQLException(DB.java:383)
    12:25:41 [SEVERE]      at org.sqlite.DB.newSQLException(DB.java:387)
    12:25:41 [SEVERE]      at org.sqlite.DB.throwex(DB.java:374)
    12:25:41 [SEVERE]      at org.sqlite.NativeDB.prepare(Native Method)
    12:25:41 [SEVERE]      at org.sqlite.DB.prepare(DB.java:123)
    12:25:41 [SEVERE]      at org.sqlite.PrepStmt.<init>(PrepStmt.java:42)
    12:25:41 [SEVERE]      at org.sqlite.Conn.prepareStatement(Conn.java:404)
    12:25:41 [SEVERE]      at org.sqlite.Conn.prepareStatement(Conn.java:399)
    12:25:41 [SEVERE]      at org.sqlite.Conn.prepareStatement(Conn.java:383)
    12:25:41 [SEVERE]      at lib.PatPeter.SQLibrary.Database.prepare(Database.java
    :192)
    12:25:41 [SEVERE]      at me.sharp237.testplugin.TestPlugin.onRightClick(TestPl
    ugin.java:94)
    12:25:41 [SEVERE]      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native M
    ethod)
    12:25:41 [SEVERE]      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown S
    ource)
    12:25:41 [SEVERE]      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unkno
    wn Source)
    12:25:41 [SEVERE]      at java.lang.reflect.Method.invoke(Unknown Source)
    12:25:41 [SEVERE]      at org.bukkit.plugin.java.JavaPluginLoader$1.execute(Jav
    aPluginLoader.java:339)
    12:25:41 [SEVERE]      at org.bukkit.plugin.RegisteredListener.callEvent(Regist
    eredListener.java:62)
    12:25:41 [SEVERE]      at org.bukkit.plugin.SimplePluginManager.fireEvent(Simpl
    ePluginManager.java:477)
    12:25:41 [SEVERE]      at org.bukkit.plugin.SimplePluginManager.callEvent(Simpl
    ePluginManager.java:462)
    12:25:41 [SEVERE]      at org.bukkit.craftbukkit.event.CraftEventFactory.callPl
    ayerInteractEvent(CraftEventFactory.java:177)
    12:25:41 [SEVERE]      at net.minecraft.server.ItemInWorldManager.dig(ItemInWor
    ldManager.java:114)
    12:25:41 [SEVERE]      at net.minecraft.server.NetServerHandler.a(NetServerHand
    ler.java:549)
    12:25:41 [SEVERE]      at net.minecraft.server.Packet14BlockDig.handle(SourceFi
    le:46)
    12:25:41 [SEVERE]      at net.minecraft.server.NetworkManager.b(NetworkManager.
    java:282)
    12:25:41 [SEVERE]      at net.minecraft.server.NetServerHandler.d(NetServerHand
    ler.java:111)
    12:25:41 [SEVERE]      at net.minecraft.server.ServerConnection.b(SourceFile:35
    )
    12:25:41 [SEVERE]      at net.minecraft.server.DedicatedServerConnection.b(Sour
    ceFile:30)
    12:25:41 [SEVERE]      at net.minecraft.server.MinecraftServer.r(MinecraftServe
    r.java:569)
    12:25:41 [SEVERE]      at net.minecraft.server.DedicatedServer.r(DedicatedServe
    r.java:215)
    12:25:41 [SEVERE]      at net.minecraft.server.MinecraftServer.q(MinecraftServe
    r.java:486)
    12:25:41 [SEVERE]      at net.minecraft.server.MinecraftServer.run(MinecraftSer
    ver.java:419)
    12:25:41 [SEVERE]      at net.minecraft.server.ThreadServerApplication.run(Sour
    ceFile:818)
    12:25:51 [INFO] leftclick block
    12:25:51 [INFO] Unable to log to Sqlite DB!
    12:25:51 [SEVERE] java.sql.SQLException: [SQLITE_BUSY]  The database file is loc
    ked (database is locked)
    12:25:51 [SEVERE]      at org.sqlite.DB.newSQLException(DB.java:383)
    12:25:51 [SEVERE]      at org.sqlite.DB.newSQLException(DB.java:387)
    12:25:51 [SEVERE]      at org.sqlite.DB.throwex(DB.java:374)
    12:25:51 [SEVERE]      at org.sqlite.NativeDB.prepare(Native Method)
    12:25:51 [SEVERE]      at org.sqlite.DB.prepare(DB.java:123)
    12:25:51 [SEVERE]      at org.sqlite.PrepStmt.<init>(PrepStmt.java:42)
    12:25:51 [SEVERE]      at org.sqlite.Conn.prepareStatement(Conn.java:404)
    12:25:51 [SEVERE]      at org.sqlite.Conn.prepareStatement(Conn.java:399)
    12:25:51 [SEVERE]      at org.sqlite.Conn.prepareStatement(Conn.java:383)
    12:25:51 [SEVERE]      at lib.PatPeter.SQLibrary.Database.prepare(Database.java
    :192)
    12:25:51 [SEVERE]      at me.sharp237.testplugin.TestPlugin.onRightClick(TestPl
    ugin.java:94)
    12:25:51 [SEVERE]      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native M
    ethod)
    12:25:51 [SEVERE]      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown S
    ource)
    12:25:51 [SEVERE]      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unkno
    wn Source)
    12:25:51 [SEVERE]      at java.lang.reflect.Method.invoke(Unknown Source)
    12:25:51 [SEVERE]      at org.bukkit.plugin.java.JavaPluginLoader$1.execute(Jav
    aPluginLoader.java:339)
    12:25:51 [SEVERE]      at org.bukkit.plugin.RegisteredListener.callEvent(Regist
    eredListener.java:62)
    12:25:51 [SEVERE]      at org.bukkit.plugin.SimplePluginManager.fireEvent(Simpl
    ePluginManager.java:477)
    12:25:51 [SEVERE]      at org.bukkit.plugin.SimplePluginManager.callEvent(Simpl
    ePluginManager.java:462)
    12:25:51 [SEVERE]      at org.bukkit.craftbukkit.event.CraftEventFactory.callPl
    ayerInteractEvent(CraftEventFactory.java:177)
    12:25:51 [SEVERE]      at net.minecraft.server.ItemInWorldManager.dig(ItemInWor
    ldManager.java:114)
    12:25:51 [SEVERE]      at net.minecraft.server.NetServerHandler.a(NetServerHand
    ler.java:549)
    12:25:51 [SEVERE]      at net.minecraft.server.Packet14BlockDig.handle(SourceFi
    le:46)
    12:25:51 [SEVERE]      at net.minecraft.server.NetworkManager.b(NetworkManager.
    java:282)
    12:25:51 [SEVERE]      at net.minecraft.server.NetServerHandler.d(NetServerHand
    ler.java:111)
    12:25:51 [SEVERE]      at net.minecraft.server.ServerConnection.b(SourceFile:35
    )
    12:25:51 [SEVERE]      at net.minecraft.server.DedicatedServerConnection.b(Sour
    ceFile:30)
    12:25:51 [SEVERE]      at net.minecraft.server.MinecraftServer.r(MinecraftServe
    r.java:569)
    12:25:51 [SEVERE]      at net.minecraft.server.DedicatedServer.r(DedicatedServe
    r.java:215)
    12:25:51 [SEVERE]      at net.minecraft.server.MinecraftServer.q(MinecraftServe
    r.java:486)
    12:25:51 [SEVERE]      at net.minecraft.server.MinecraftServer.run(MinecraftSer
    ver.java:419)
    12:25:51 [SEVERE]      at net.minecraft.server.ThreadServerApplication.run(Sour
    ceFile:818)
    >
    Please could someone tell me what I need to change in the code for this not to happen?
    PatPeter
    ferrybig
    Sleaker
    hockeygoalie5
     
  24. Offline

    Sushi

    Something else is accessing the database while you are running the server
     
  25. Offline

    sharp237

    Another plugin? Could it be a program installed on my computer?

    I think it must be a program or something on my PC ... :/ I sent it to my friend who has a dedicated server host and he uploaded it and it worked fine on there even after restarting. Lol, I have literally spent a few months trying to debug sqlite; thinking my code was all wrong. After all that it turns out its my f***ing computer! :mad:


    Genuis ------ > Sushi THANKYOU sooooooooo much!!!!!!! [cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake][cake]
    Do you know how I could find out what program/software is interfering with it?

    Also, when I reload even on the server host it stops working. But if I stop the server and start it again then it will work on the server host :)

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

    Sushi

    Not really. Also, you might be opening a connection without closing it?
     
  27. Offline

    sharp237

    How would I know if I am doing this?
     
  28. Offline

    Sushi

    Your code. You have to close sqlite connections...
     
  29. Offline

    sharp237

    Have I not closed them all? I thought I did :/
     
  30. Offline

    PatPeter

    Just make sure you close every ResultSet with SQLite. If you don't close all of them you'll get the same error.

    And you should add your SQLite plugin back into your main plugin. The whole point of my library is so that you don't have to do that.
     
Thread Status:
Not open for further replies.

Share This Page