Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data storage in Java

Tags:

java

database

I am doing a little programming exercise in Java to get me back into the swing of things before school. My program will be video game (Team Fortress 2) related and as such I need to store data about a large number of weapons.

My current model is that I have a class for each type of weapon, (e.g. Scout_Primary or Soldier_Secondary) and I will modify the variables in each class depending on what specific weapon is selected. For example if Scout_Primary is "Scattergun" I will modify its base damage and reload speed accordingly.

If you are familiar with TF2 you will know that there is a large amount of weapons. How do I store all the weapons' stats in my program? I do not wish to write giant switch statements containing stats for each weapon in a category. I am very eager to work with SQL more (I have some experience with it but not too much, I have used JDBC before).

Is it possible to create a database and just package it with the program itself so that I don't have to worry about hosting? The only experience I have is with remote databases.

What I would like to do would be to have that local database and perform Selects and pass the data to a constructor. Thanks in advance.

EDIT: I have been looking at Derby, is this the right direction?

like image 615
0nyx Avatar asked Dec 03 '25 17:12

0nyx


1 Answers

Yes, SQL could be appropriate for this. You should look into Apache Derby, its main benefit is that it is lightweight and very easy to embed into a Java application. You can do exactly what you're talking about - use it locally.

The only issue will be bundling the actual data with your application. I would suggest you start with it in a simple file, maybe JSON or XML encoded, or even just CSV - basically anything you choose. Then when the program starts, you check to see if the database exists. If not, you create it, read the file, and store the data from the file into the database. Then you're ready to do querying with SELECT statements or whatever else you want.

like image 177
Joe K Avatar answered Dec 06 '25 10:12

Joe K