Best DBs to Use With Java
Tags: database, java, sql
Published: 2022-12-20 20:08:00

At some point during your programming journey, you’ll need a database. But which one? Choosing a database can be challenging, especially if you don’t know what to look for.

## How to find the right database for your needs
DB-Engines is an initiative to collect and present information on database management systems (DBMS), and they maintain a ranking of DBMS by popularity. These rankings are updated monthly. While popularity doesn’t necessarily imply “best”, it is a good starting point when evaluating databases. In this article, we’ll explore some of the top databases as identified by DB-Engines, and compare the DB-Engines ranking to the available StackOverflow survey data.

## Some database basics

Before we dive into the rankings, though, let’s chat databases. A database is a collection of information, or data. Databases come in a variety of types, ranging from relational to object-oriented, NoSQL, and more. As of writing, the top five databases on DB-Engines are either relational or NoSQL, so we’ll be focusing on just those two types of databases here. For information on other types of databases, you can check out this article.

Relational databases are perhaps the most traditional type of database. Items are stored in tables with columns and rows, and typically queried through SQL (Structured Query Language)– think lots of SELECT * and INNER JOINs. On the flip side, NoSQL databases are non-tabular, great for flexible schemas and scaling. They were developed in the late 2000s with a focus on scaling, fast queries, frequent application changes, and simpler programming.

## The rankings

### MySQL

Ranked second by DB-Engines, MySQL was released in the mid-90s. It made its way to Oracle Corporation through a series of acquisitions, and was forked to become MariaDB in 2010. MySQL is an open-source RDBMS and can be queried using SQL. Though it’s ranked second on the DB-Engines list, MySQL is actually the top relational database choice for Java developers, at least according to the StackOverflow 2021 survey — 55.48% of respondents have used it / want to use it.

### MongoDB

The top NoSQL option on our list (and the only NoSQL option within the top five list on DB-Engines!), MongoDB is a source-available distributed document database. Document databases store data in documents, similar to JSON. In the MongoDB case, data is stored as BSON (binary representation of JSON) documents that are gathered together to make collections. A database is one or more collections of documents. Unlike the traditional database format of tables with rows and columns, the document model is more flexible. MongoDB was first released in 2009, making it the (relative) newcomer on this list. 30% of Java developers have used it or want to use it.

### Microsoft SQL Server

SQL Server is a Microsoft product and another RDBMS. Unlike MySQL, SQL Server is not open source, but it does have both paid-tier and free-tier options. SQL Server was first released in the 1980s. It can be queried through (you guessed it) SQL. About a quarter of the StackOverflow Java respondents have used/want to use it (23.66%).

### PostgreSQL

Sometimes just called Postgres, PostgreSQL is a free and open-source RDBMS. It’s been on the market a bit more than 25 years; its first release was in the mid-90s. It’s extremely popular — 40.44% of Java developers have used it or want to use it.

### Oracle

Oracle was first released in the 1970s by Oracle Corporation, the first company to commercialize relational databases. Oracle is a relational database that can be queried through SQL. Oracle’s a great fit if you know your schema won’t change, as schema changes require migrations (which can be painful!). It’s also a bit complex, so it might not be a great fit if you just want something quick. On the flip side, if you enjoy SQL and want something enterprise-level, Oracle is an excellent choice. Interestingly, though DB-Engines ranks Oracle as its top choice, the respondents to the StackOverflow 2021 survey don’t necessarily agree. Only 20.24% of Java developers who responded to the survey have used Oracle in the past year or want to work with Oracle in the next year.