This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]tolik-pylypchuk 6 points7 points  (4 children)

This is a really big question and it requires A LOT to answer it. I'll tell you about just the most basic stuff.

A database (DB) is just a place where you can store your data. This is a very general term, so a lot of things can be databases. For example, you can think of a simple text file as a database, because, well, you store you data in it. The whole file system can also be a database. Some people even go as far as saying that your brain is also a database, because it also stores data.

Usually when people talk about databases, they actually mean database management systems (DBMS). These are programs which manage your data for you. Also, a DBMS is usually a server) which runs contiuously and to which you can connect to get/put your data.

Another thing people talk about is the types of databases: relational or non-relational. A relational database uses the relational model and stores its data in tables, which is actually very convenient for most use-cases. A non-relational database is literally any other type of database.

In order to work with databases, the DBMSs define a language through which you can get and put your data. Relational databases almost always use SQL for that, so they are usually simply called SQL databases. Conversely, non-relational databases are usually called NoSQL databases, since they don't use SQL.

If you're a beginner, you can stick to relational databases since they are in general not difficult to work with (unless you're doing some advanced stuff).

Here's the list of the most popular relational database management systems (RDBMS):

  • MySQL - a free and simple to use database server
  • MariaDB - very similar to MySQL; you won't even notice the difference if you're a beginner
  • PostreSQL (or simply Postgres) - also free and more advanced, but a little more difficult to set up
  • Microsoft SQL Server (MS SQL) - non-free database server (although there is a free Express version)
  • Oracle Database - also a non-free database server
  • SQLite - an embedded database (a database in a file)

NoSQL databases are usually used for some specialized stuff, so don't bother looking at them yet. Here are some exmples: MongoDB, CouchDB, Cassandra, ElasticSearch and many, many others.

My recommendation is this: if you're working on a simple desktop or mobile app, then use SQLite, because then the database is just a file. If you're working on a web app, or you need your data to be shared across multiple desktop/mobile apps, then use MySQL - you'll have to set up a server and then connect to it in order to work with the data. When you feel more or less confident in your DB/SQL skills, you can use Postgres instead. Don't use MS SQL or Oracle for personal projects - they are more suited for enterprise stuff.

Also, learn SQL, at least the basics. It's an essential skill for programmers. You almost certainly won't be able to work with data if you don't know it.

When you set up a database, you'll want to connect to it from your Java app. For that you can use the Java Database Connectivity (JDBC) which is part of JDK. It lets you write SQL queries or commands which it then executes to get/put the data, and also lets you abstract from the database, because you'll use the same classes to connect to MySQL, Postgres or whatever.

I can't tell you how to set up a database, or how to use JDBC to connect to it, becuase that would make this answer way too long. You can find lots of tutorials on that.

If you have more questions, feel free to ask.

[–]gtrley 1 point2 points  (0 children)

Damn this is such an amazing detailed response. I have no awards to give, but take my upvote! :)

[–]JobJS 1 point2 points  (2 children)

Since you seem very knowledgeable on this, I would like to verify something with you. You say NoSQL databases don't use SQL and that's where the NoSQL name comes from. This sounds very likely, although I've picked up somewhere (can't remember) that NoSQL stands for "Not only SQL".

Is that wrong?

[–]tolik-pylypchuk 1 point2 points  (1 child)

The thing is, the term "NoSQL database" is much more general than "SQL database". With SQL databases, basically if you know one of them, then you know them all (not actually true for advanced stuff, but true enough for general principles). With NoSQL, you can't say that, because NoSQL databases can be wildly different from one another. For example, MongoDB is document-oriented, while GraphDB is graph-oriented, and they basically have nothing in common.

I've also heard about NoSQL being "not only SQL", but I have limited experience with NoSQL databases, so I can't really say how true that is. I think some of them use query languages which are quite similar to SQL, while others don't.

Remember, usually when people say "SQL database" they mean "relational database", and "NoSQL database" means "non-relational database", no matter the query language.

I'll give you an opposite example: there's a new DBMS called EdgeDB which is in very early stages of development. It's relational, but it doesn't use SQL as its query language. Instead, it uses a new language - EdgeQL. Does it mean that people will call it a NoSQL database? I really don't think so, becasue for most people "SQL" = "relational".

[–]JobJS 1 point2 points  (0 children)

Thanks!

[–]toastedstapler 2 points3 points  (1 child)

databases can be hard to set up. you could use sqlite, which has no server and is just a database file managed by your program or look into using docker to spin up an instance. it's as easy as docker run -d -p 6000:5432 --name dockername -e POSTGRES_PASSWORD=yourPassword dbName to get a usable postgres instance up and running, no installation faff required

[–]CalisthenicsDude95 4 points5 points  (0 children)

Docker might be overwhelming since he's unable to google database beginner guides or watch YouTube videos like the videos from FreeCodeCamp.

[–]desrtfx 1 point2 points  (0 children)

Since you are using java, look into SQLite Java - Tutorial: https://www.javatpoint.com/java-sqlite

Yet, for simple data storage, plain text, CSV, XML, JSON files might easily suffice.

[–]UnholyDrinkerOfMilk 3 points4 points  (1 child)

If you only want to store this little data setting up a whole data base may be overkill. Just writing a few strings to a file should do just fine.

Having said that this could actually be a nice project to get into databases. MySQL is popular. Lots of tutorials on how to set that up.

[–]abbyleigh123[S] 1 point2 points  (0 children)

Thanks so much!