When you write an application, it's common to require data storage. Sometimes you're storing assets your application needs to function, and other times you're storing user data, including preferences and save data. One way to store data is in a database, and in order to communicate between your code and a database, you need a database binding or connector for your language. For Java, a common database connector is JDBC (Java database connectivity.)

1. Install Java {#_1_install_java}

Of course, to develop with Java you must also have Java installed. I recommend

SDKman

for Linux, macOS, and WSL or Cygwin. For Windows, you can download OpenJDK from

developers.redhat.com

.

2. Install JDBC with Maven {#_2_install_jdbc_with_maven}

JDBC is an API, imported into your code with the statement `import java.sql.*`, but for it to be useful you must have a database driver and a database installed for it to interact with. The database driver you use and the database you want to communicate with must match: to interact with MySQL, you need a MySQL driver, to interact with SQLite3, you must have the SQLite3 driver, and so on.

For this article, I use

PostgreSQL

, but all the major databases, including

MariaDB

and

SQLite3

, have JDBC drivers.

You can download JDBC for PostgreSQL from

jdbc.postgresql.org

. I use

Maven

to manage Java dependencies, so I include it in `pom.xml` (adjusting the version number for what's current on

Maven Central

):

3. Install the database {#_3_install_the_database}

You have to install the database you want to connect to through JDBC. There are several very good open source databases, but I had to choose one for this article, so I chose PostgreSQL.

To install PostgreSQL on Linux, use your software repository. On Fedora, CentOS, Mageia, and similar:

On Debian, Linux Mint, Elementary, and similar:

Database connectivity {#_database_connectivity}

If you're not using PostgreSQL, the same general process applies:

1. Install Java.

2. Find the JDBC driver for your database of choice and include it in your `pom.xml` file.

3. Install the database (server and client) on your development OS.

Three easy steps, and you're ready to start writing code. In my next article, I'll show you how to use JDBC with PostgreSQL.

Proxied content from gemini://sdf.org/klaatu/geminifiles/jdbc.gmi (external content)

Gemini request details:

Original URL
gemini://sdf.org/klaatu/geminifiles/jdbc.gmi
Status code
Success
Meta
text/gemini
Proxied by
kineto

Be advised that no attempt was made to verify the remote SSL certificate.