Solved Making a .db and read/write to it!

Discussion in 'Plugin Development' started by RainoBoy97, Oct 12, 2012.

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

    RainoBoy97

    Ive seen plugins which uses a .db file to store data in. I believe this is a "simple" database file, instead of a mySQL. And currently im working on a KitPVP plugin for my server, and want to use a .db file to store data.
    Is there any easy understandable guide for this?
    Thanks!

    -Raino
     
  2. Offline

    Njol

    I guess that they use Java's serialization to save some Map or other data to a .db file (some prefer to use an .obj file for this though it doesn't matter at all)
     
  3. Offline

    RainoBoy97

    Hmmmm, Im sorry but i didnt understand anything on the link :/
     
  4. Offline

    Njol

    What kinds of data do you want to save? You might find it easier to use a YAML config file if possible.
     
  5. Offline

    RainoBoy97

    Yea, i know. Just thought it would be cooler with a .db file xD

    I think i need/want to store warp locations (x, y, z, yaw, pitch), players ip (without port), kits, messages and ban (with reason)!
     
  6. Offline

    Njol

    Since neither Locations nor ItemStacks are serializable I suggest to use a YAML config to store the data (you can even store it as .db if you want to ;) ).
    Create some code which saves all data to a file in onDisable() and code that loads it back in onEnable(), e.g. by looping a map and storing everything as config.set(name, value), or looping the config and saving it in a map respectively.

    BTW: You can learn how to make a config with a different file name than 'config.yml' on the wiki
     
  7. Offline

    RainoBoy97

    Thanks for the help, Im now using a .db to store my data!
    Thanks man!
     
  8. Offline

    Devil0s

    That's ridiculous.
     
  9. Offline

    RainoBoy97

    Eeeeh?
     
  10. Offline

    Tzeentchful

    A .db file is usually a SQLite database, it's basically a sql database in one file. I would recommend looking into SQLibrary.
     
  11. Offline

    Devil0s

    If you want to be "cool" you shouldn't learn programming but American Football, Rugby, DJing etc...
     
    kroltan likes this.
  12. Offline

    nathanaelps

    With all due respect, programming databases is dang awesome. If this is how @RainboBoy97 gets introduced to something that he loves, then let him think it's the coolest thing ever--because for him, at least, it could be. And writing a plugin for bukkit is a far better way to learn where databases are relevant and where they're not than (say) writing a records-keeping program for a chain of hospitals across the Great Plains.

    And if you think that rugby is cooler, that's fine! Pursue your cool, and be sure to get plenty of video because 1) You can learn from your bad plays that way, 2) YouTube will pay you if you have enough subscribers, and 3) You won't be able to play rugby when you're 80, so be sure you get the memories on tape.
     
  13. Offline

    Hoolean

    Respect. :D
     
    RainoBoy97 likes this.
  14. Offline

    RainoBoy97

    I did the same thing that you would do to generate/read and write to a .yml file, but instead i changed the .yml to .db. Works just as good :p

    I wanted to do this so I can start to learn how to store data in more complex ways, like SQL and mySQL.....
    Haha, thanks for the support! .... Btw, you spelled RainoBoy97 wrong xD Hehe..
     
  15. Offline

    Hoolean

    Awh... I liked @RainboBoy97 :D
     
  16. Offline

    TwistedMexi

    Support all the way for wanting to expand your skillset, but to clarify: Changing a .yml file to .db and reading it as you would a config file does not make it an actual database in any shape or form. If you still wish to implement a real database, you're not there yet. As long as you understand you're still just reading the file and are ok with it, then I am too. :)
     
  17. Offline

    RainoBoy97

    Hehe!
    Yeah, I have to learn to serealize or whats it called xD
     
  18. Offline

    Devil0s


    I respect that he prefer databases to save their data but I think his reason is ridiculous.
    You misunderstood me. I love programming and I think that no one need a reason to learn a new way to store data (or to do anything).
    But it's ridiculous that someone think up a very strange reason to hide his true feelings about programming. ;)
    I dont know whether Rugby etc.. is cool (in my country the most guys doesnt play it but I think so).
    And I dont think that 80 years old people does programming (or will). ;)

    Devil0s
     
  19. Offline

    nathanaelps

    Oh. Uh. Lol, sorry, man. That would explain why it didn't tag you properly...

    Yeah, it's cool. I wasn't meaning to say that you're a terrible person (or anything like that). I think that Raino actually _does_ think that DB's are cool... And they are, kinda. (OK, honestly? Databases freak me out and make me angry, but... different strokes, and all that...)

    Go ahead and think that his reason is silly... But please help him, encourage him, and try to see the db through his eyes. That's how we get an awesome Bukkit community.

    Also, if I'm not programming when I'm 80 it better be because my fingers fell off. :D
     
    RainoBoy97 and kroltan like this.
  20. Offline

    Devil0s

    I am trying to learn storing files in a db too.
    So I can't help him. ;)
    Do you know any open source plugins that use .db files.
    But please do not post PermissionsEx or anything like that (not so huge).
    It's better if it is a simple plugin with only one feature or two.
    It would help so much if I can see a code of another plugin.

    Thanks Devil0s
     
  21. Offline

    RainoBoy97

    Should be more guys like you on this forum :p
     
  22. Offline

    Devil0s

    Exactly. :D
     
Thread Status:
Not open for further replies.

Share This Page