[INACTIVE] SQLite and MySQL Tutorial/Library

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

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

    Lolmewn

    What should it be then? :p
     
  2. Offline

    Jayjay110

    Oh, is that what you mean...or something lol dw about it :3
     
  3. Offline

    Lolmewn

    Ok we're getting a little off-topic :p I need to get that SQL working, I hope @alta189 knows why it's failing.
     
  4. Offline

    Jayjay110

    I figured out ur error :)
    its :
    query = "SELECT * FROM skillz WHERE player='" + p + "';";
    not what you did, you forgot to end the sql statement with a semi colon, and you should leave a gap between the quote and the equals sign, I think that this should fix it :D
     
  5. Offline

    Lolmewn

    Let me just check that for you :p

    btw, ending has to be everywhere right?

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

    Jayjay110

    ending?
     
  7. Offline

    Lolmewn

    A ; thingy. I call it an ending :p
     
  8. Offline

    Jayjay110

    Rofl :D its called a semi-colon but yer lol, yeh every statement has an end i believe

    EDIT:
    Wow lol look, I signed up 6 days after u!
     
  9. Offline

    Lolmewn

    7 days ;)
     
  10. Offline

    Piddu

  11. Offline

    Lolmewn

    Is this code OK?
    Code:
    String query;
    query = "INSERT INTO skillz (player, skill, xp, level) values ('" + p + "', 'acrobatics' , 0 , 0);";
                    plugin.dbManager.sqlQuery(query);
    
    Cuz I'm getting this error:
    16:03:04 [WARNING] [Skillz] Error at SQL Query: query does not return ResultSet
     
  12. Offline

    alta189

    use:
    Code:
    String query;
    query = "INSERT INTO skillz (player, skill, xp, level) values ('" + p + "', 'acrobatics' , 0 , 0);";
                  [CODE] plugin.dbManager.insertQuery(query);
     
  13. Offline

    Lolmewn

    I was JUST about to ask a question when I found the answer =D
    I was acting stupid and asked the table for the actual CommandSender Player data :p
    While of course I needed ((Player)player).getName xD Ah well, Thnx, because it works!
     
  14. Offline

    Lolmewn

    I've got another problem.. Sorry to bother. Really. Here is some code:
    Code:
    String query1 = "SELECT id, player, skill, xp, level FROM skillz WHERE player = '"+ p.getName() + "' AND skill = '" + skill + "';";
                ResultSet set = dbManager.sqlQuery(query1);
                int back = dam;
                if(set == null){
                    p.sendMessage("Something went Horribly wrong while processing this!");
                }
                try {
                    p.sendMessage(set.toString());
                    xp = set.getInt("xp");        //<---- THIS IS THE LINE WHEN THE ERROR IS HERE
                    String query2 = "UPDATE skillz SET xp='"+ back +"' WHERE xp='" + xp + "' AND player='" + p.getName() + "' AND skill='" + skill + "';";
                    dbManager.updateQuery(query2);
                    checkLeveling(skill, p, xp, dam);
                } catch (SQLException e) {
                    e.printStackTrace();
                }p
    What it returns (to the player) is this:
    org.sqlite.RS@637533df

    And this is the error:
    Code:
    19:51:58 [SEVERE] java.sql.SQLException: ResultSet closed
    19:51:58 [SEVERE]       at org.sqlite.RS.checkOpen(RS.java:63)
    19:51:58 [SEVERE]       at org.sqlite.RS.findColumn(RS.java:108)
    19:51:58 [SEVERE]       at org.sqlite.RS.getInt(RS.java:293)
    19:51:58 [SEVERE]       at nl.lolmen.Skillz.SkillzGet.getSkills(SkillzGet.java:61)
    19:51:58 [SEVERE]       at nl.lolmen.Skillz.SkillzEntityListener.onEntityDamage(SkillzEntityListener.java:40)
    19:51:58 [SEVERE]       at org.bukkit.plugin.java.JavaPluginLoader$47.execute(JavaPluginLoader.java:570)
    19:51:58 [SEVERE]       at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:58)
    19:51:58 [SEVERE]       at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:310)
    19:51:58 [SEVERE]       at net.minecraft.server.EntityLiving.a(EntityLiving.java:493)
    19:51:58 [SEVERE]       at net.minecraft.server.EntityHuman.a(EntityHuman.java:829)
    19:51:58 [SEVERE]       at net.minecraft.server.Entity.a(Entity.java:646)
    19:51:58 [SEVERE]       at net.minecraft.server.EntityPlayer.b(EntityPlayer.java:333)
    19:51:58 [SEVERE]       at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:343)
    19:51:58 [SEVERE]       at net.minecraft.server.Packet10Flying.a(SourceFile:126)
    19:51:58 [SEVERE]       at net.minecraft.server.NetworkManager.b(NetworkManager.java:215)
    19:51:58 [SEVERE]       at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:75)
    19:51:58 [SEVERE]       at net.minecraft.server.NetworkListenThread.a(SourceFile:105)
    19:51:58 [SEVERE]       at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:396)
    19:51:58 [SEVERE]       at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:308)
    19:51:58 [SEVERE]       at net.minecraft.server.ThreadServerApplication.run(SourceFile:422)
    anyone? @alta189 maybe? or @Jayjay110 ?

    Yay! Found it <3
    I forgot the while(res.next()){} thingy.

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

    alta189

    Sorry, on vacation. I will be slow to answer for a week :D
     
  16. Offline

    Lolmewn

    Ok sure =D Go enjoy your holiday, I think i'll magage (Damn you error! Get out!)
     
  17. Offline

    alta189

    Are you still having errors?
     
  18. Offline

    Jayjay110

    I have an addition you should add to ur code to make it check for the database and create a new one, would u like it?
     
  19. Offline

    alta189

    Sure you can send it to me :p, I was actually just getting ready to start working on that :p

    Over my time on "vacation", I will start to work on the Documentation so that it will be easy to find. :p After I do all these updates I am so tired of typing I dont feel like doing it :p
     
  20. Offline

    Lolmewn

    Well, it's not an error, but it doesn't quite update. Im making my code shorter now, to see if that randomly works, Ill send you some code after.

    Here's some code:
    Code:
    query = "SELECT * FROM skillz WHERE player = '" + p.getName() + "' AND skill = '" + skill + "';";
                ResultSet set = dbManager.sqlQuery(query);
                if(set == null){
                    p.sendMessage("Something went Horribly wrong while processing this!");
                    return;
                }
                try {
                    while(set.next()){
                        xp = set.getInt("xp");
                    }
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
                int back = dam + xp;
                Skillz.log.info(xp + "," + back);
                query = "UPDATE skillz SET xp=" + back + " WHERE skill='" + skill + "' AND player='"+ p.getName() + "';";
                dbManager.updateQuery(query);
                checkLeveling(skill, p, xp, back);
    CheckLeveling:
    Code:
    public static void checkLeveling(String skill, Player p, int before, int after){
            int newXP = after;
            if(before<1 && (newXP>1 || newXP==1)){
                String args = getMessage(skill, 1);
                p.sendMessage(args);
                levelup(skill, p,1);
            }
    levelup:
    Code:
    String query = "UPDATE skillz SET level="+ lvl +" WHERE player='" + p.getName() + "' AND skill='" + skill + "';";
                dbManager.updateQuery(query);
    What happens? I get the message that I level up every time I jump off something (the int dam = 2), and when I check my stats it gives 0 and 0. (So the XP is still 0 and the level aswell). It should go to 2 and 1 though. What am I doing wrong?

    @alta189 is enjoying his vacation :p

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

    alta189

    When using a WHERE statement do not put ' around ints only around strings
     
  22. Offline

    Lolmewn

    Eeh, I don't quite see where I have that. In which of the code blocks was it?
     
  23. Offline

    alta189

    all of the queries
     
  24. Offline

    Lolmewn

    But skill is a String and Player is a string aswell. Only back is not, I dont have ' thingys there.
     
  25. Offline

    cronikkk

    make it level = '" + lvl + "'
    Don't forget the '
     
  26. Offline

    alta189

    Thanks cronikkk. @Lolmewn listen to him. He is the MySQL expert. :D
     
  27. Offline

    cronikkk

    Yezzir
     
  28. Offline

    Lolmewn

    Oh I thought you didnt have to put any ' thinys @ integers.
     
  29. Offline

    alta189

    I guess you do. Cronikkk is on the dev team that I started called MineDev, anyways he used to be a PHP/MySQL programmer so I would trust him with queries :D
     
  30. Offline

    Lolmewn

    Okies =D Thnx for tha help! Cronikkk aswell :p

    It's finally working! I just had to not-uppercase a string.. (omg)

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

Share This Page