Why Do I Need To Know about Databases?

You would be forgiven for thinking that databases are only useful in business software and similar apps, but in reality, they can be used as an excellent form of data storage for Java games on a server. The only other real option that we have other than databases is using files on the server to store the data, but the access would be much slower and files can become corrupt much more easily. In contrast to that though, the simplest type of database is a flat file database, which constitutes the use of normal text files to structure a relational database. This is commonly done with the use of CSV (comma-separated values) to represent the fields of data within the tables and separate files to represent the actual tables of the database. This is how a sample table of information would look in CSV format:

Ian,Smith,24, Jenny,Wethersby,19, Harry,Ashby,43, Rachel,Henderson,32, Lucy,Jones,18,

This would represent a table that held a user's first name, surname, age, and e-mail address and would be contained in a single flat file.

Although we have little interest in flat file databases, they can be useful for storing backups of data. For example, you could export a database into CSV and write it to a DVD every day to ensure that you have a safe backup. CSV is very easy to import into a database, and we will see this in the next chapter on using a real database package.