The first time I had to save data from a Java program into a database, I was sure there would be a different library for every database. One for MySQL, one for Oracle, one for PostgreSQL, each with its own commands to learn.
It turns out Java solved this problem a long time ago, with one standard called JDBC . You learn it once, and the same code works with almost any relational database. You mostly just swap one small jar file and one line of text.
In this post, we'll learn what JDBC is, what a JDBC driver does (and which one to use for each database), the steps of every JDBC program, a complete working example with an explanation of each line, the different execute methods, the three kinds of statements and when to use each, and the best practices that keep your code safe and fast.…