Hi,
This question is about whether it’s worth learning SQL or if I should roll-my-own data storage using HashMaps and serialisation so that I can leverage my knowledge of Java to manipulate data.
I have a (sort-of-a-game-but-not-really) hobby project web app programmed in java and hosted using Tomcat here: www.fightfinance.com.
For storage I’ve been using the SQL database H2(http://www.h2database.com/) which has been excellent. On Riven’s advice, I use only prepared statements and access the database through a ‘user access object’ which is just a class that holds all of the SQL code to do things. This has worked well so far for my simple queries.
The problem is that I now have some data and I want to do more interesting things with it, like delete (spamming) players and every bit of data associated with them (questions, answers, questions edits, ip address logs). Or find the hardest questions which have the highest proportions of wrong answers.
But my knowledge of SQL is so poor that I don’t know how to structure these queries. I could easily manipulate the data if it was a HashMap or List in java, but making SQL statements is a pain in the butt. Usually I find myself trawling stackoverflow for example code which I try to adapt but I don’t really understand, or I pull in whole tables out of the SQL database and dump it into ArrayLists in my java code and then sort thru it there which must be quite inefficient.
I’ve read about things like jooq(http://www.jooq.org/) and Empire DB(http://empire-db.apache.org/) which sound easier to use than pure SQL.
So far as I can see these are the advantages (+) of SQL/H2/jooq/empireDB:
- Stable and used by everyone.
- SQL databases have everything built in such as serialisation/persistence.
- Access on a remote server thru a web interface which is handy.
- Learning SQL might be useful for other projects or even getting a job.
Disadvantages:
- SQL is a pain, seems clumsy compared to java syntax which I already know.
- Black box and performance-wise I have no idea what’s going on in there.
- No compile-time safety at least with a pure SQL database (but there is for JOOQ and EmpireDB).
Advantages of a roll-my-own data storage setup with HashMaps and serialisation:
- High performance using HashMaps.
- All-java, no external config files or any other garbage to worry about.
- Complete control.
Disadvantages:
- Have to be careful about persistence thru serialisation when the data structure changes.
- No web-interface, I’ll have to make my own.
- database might grow so big that it can not all be stored in RAM as HashMaps on my small 256MB RAM server.
What are your thoughts? As far as I know, most people do not use databases for storing data in their games. But many of you have experience in databases from your corporate work so I thought you’d be a great bunch to ask about this.
Cheers,
Keith