Sqlite

Discussion in 'Plugin Development' started by sharp237, Mar 9, 2013.

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

    sharp237

    I am using this API for sqlite http://forums.bukkit.org/threads/lib-sqlibrary-database-wrappers-for-all-database-engines.33849/

    I am trying to see whether a row exists in a table, but I can't figure out how. I'm using this code, but it doesn't work:

    Code:
        public boolean stringCreated(String table, String column, String value){
            try
            {
                ResultSet rs = plugin.sqlite.query("SELECT * FROM " + table + " WHERE " + column + "='" + value + "'");
                if(!rs.next())
                {
                    rs.close();
                    return false;
                } else
                {
                    rs.close();
                    return true;
                }
            }
            catch(Exception e)
            {
                plugin.logger.info("Unable to log to Sqlite DB!");
            }
            return false;
        }
    PatPeter
     
  2. Offline

    Nitnelave

    Maybe you should escape the ' in your string.
    Do you get an error? Do you get Unable to log to SQlist DB? if so, it might be useful to print the error's stacktrace.
     
  3. Offline

    PatPeter

    Escaping apostrophes would actually further break it. I agree though that you need to put e.getMessage() in your catch block. You should always log the exception message. You should also change it to SQLException, as catching a general exception is bad practice.

    Otherwise, the code is fine. We need the error message.

    And remember, you could have/should have posted a thread in the SQLibrary help forum:

    http://dev.bukkit.org/server-mods/sqlibrary/forum/help/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
Thread Status:
Not open for further replies.

Share This Page