Solved Errors working with ResultSets - jdbc

Discussion in 'Plugin Development' started by mike546378, Feb 23, 2014.

Thread Status:
Not open for further replies.
  1. hello, I am developing a plugin for my server which, when the player votes, it stores info on that vote in a sqlite database (playername, voted boolean, time of vote (BIGINT), number of groups user has (Integer)). When they vote it gives them a special rank for 24 hours and then removes it once the time is up. I have it storing information inside the database and giving them the required rank, the problem comes when I try to read the stored info via a ResultSet generated by a query. Here is the code thats giving me issues: http://pastebin.com/RxnYwMSF
    When I use /voter unvote <playername> I get a java.sql.SQLExeption: ResultSet closed error on line 10, same error on use of /voter check <playername> but on line 39.
    If I try to call rs.isClosed() I get this AbstractMethodError: http://i.imgur.com/UgGKkAw.png

    Any help is much appreciated, been stuck on this for a couple weeks now :/
    Thanks in advance
    -Mike
     
  2. bumping this up, could use the help
     
  3. still looking for this, surely someone here must have jdbc experience?
     
  4. Offline

    Wizehh

    Can you post your MySQL connection classes?
     
  5. Wizehh or anyone else able to help? Trying now to bump this up too often but don't really have a choice :(
     
  6. Offline

    diage

    I am not positive, but if I had to take a wild guess, your search isn't returning anything.
     
  7. diage Could be, don't see any reason why it wouldn't return anything though. Used an external program to confirm there is data in the table
     
  8. Offline

    diage

    I just happen to recall that if a ResultSet doesn't have anything in it, it closes.
     
  9. mike546378
    The ResultSet pointer will be set to null.

    You need to call rs.next() before polling the result set for data. Doing this will move the pointer to the first result.
     
    hexaan likes this.
  10. Offline

    hexaan

    mike546378
    Adamki11s Is right you should call rs.next(); but make sure you do that in an if statements to prevent getting an error if the resultset is empty.
    Code:java
    1.  
    2. Statement st = SQLConnect.sqlConnection();
    3. ResultSet rs = st.executeQuery("Select playername,voted,lastvote,groups FROM users WHERE playername='"+args[1]+"';");
    4. if(rs.next()){
    5. int groups = rs.getInt("groups");
    6. if(groups == 1){
    7. plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), "manudel " + args[1]);
    8. }else{
    9. plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), "manudelsub "+args[1]+" VIP");
    10. }
    11. }
    12.  
     
  11. hexaan Adamki11s Thank you, no longer receiving the error however for some reason rs.getBoolean("voted") is returning false every time, even when it should definitely be true and an external program shows that it is true. Not sure why this would be as rs.getInt("groups") seems to be working perfectly fine so the db is definitely able to be read. Any suggestions on this one?

    Edit: rs.deleteRow() is throwing a "SQLException: not implemented by SQLite JDBC driver". Any alternate method/fix?
     
  12. Offline

    hexaan

    mike546378
    What datatype are you using to store your boolean? You might have to use a different value or call a different method to get the result.

    The rs.deleteRow() is probably not working because you are using a SQLite database, but I'm not sure about this.
     
  13. Offline

    Garris0n

    You should really use prepared statements.
     
  14. Garris0n I was using them before but thought they were the issue so removed them
    hexaan Yeh, think you are right about deleteRow(). Definitely using the BOOLEAN datatype to store it, no idea why it wouldn't work. ended up switching it to integer and using 1/0 as true/false, works perfectly.
    Everything is working now. Ran into another few problems but solved them myself. Thanks for all your help, much appreciated
     
  15. Offline

    hexaan

    mike546378
    Yeah I think SQLite had some issues with that datatype. I usually use 1/0 values myself.

    And no problem :)
     
Thread Status:
Not open for further replies.

Share This Page