r/JavaProgramming • u/Efficient_Pen3804 • Nov 06 '25
How do I start learning JDBC from scratch?
Hey folks,
I’m learning Java and want to understand how JDBC works, but I honestly haven’t looked up anything yet. I just know it’s used for database connections, and that’s about it.
Can someone explain how I should start learning JDBC from scratch? Also, what are the main parts or concepts I need to remember or focus on to really understand it?
I’m basically starting blind here, so any direction or explanation would help a lot.
1
u/tux2718 Nov 06 '25
JDBC is just a bunch of objects for accessing Relational Databases. Look at some example code - there’s lots out there, just Google it. The more deep thing is Relational Database Theory. When I started 40 years ago, C J Date’s book was the goto text, but it’s still a classic. If you’re looking for a database manager, consider Hyper SQL. It has embedded, server and in-memory modes that make it great for unit tests. Good Luck!
2
u/omgpassthebacon Nov 12 '25
JDBC from scratch? Wow, that takes me back. It's been a loooong time since we do it that way, but I do think it is a reasonable thing to learn. However, you will quickly see why people use DB abstractions now; JDBC is pretty low-level.
If I was going to mentor a new guy on JDBC, here is what I would suggest:
check out the JDBC docs in the JDK.java.sql from JDK21
Pick a database you can use to learn with. HyperSQL is good, or h2db. These can be run in-memory so you don't have to set up a server.
There are plenty of excellent youtubes on native JDBC. Watch a few of them to get the idea.
You will need at least a basic idea of how to use SQL to create tables and rows. Again, lots of good youtubes on this.
As a short primer, you should learn about these few classes:
java.sql.Connection - this is how you connect to a DB.
java.sql.Driver - you need one of these to use the Connection.
java.sql.Statement - a Statement encloses your SQL command. You then execute the Statement to update the DB.
java.sql.ResultSet - when you query a db, you will get back rows of data. A ResultSet is a wrapper about the rows from a SELECT.
There is a ton more, but if you can write a simple Java program that creates a table, loads some rows, then queries those rows back, you probably don't have to spend too much more time with native JDBC. You will want to use some higher-level abstraction to CRUD your data.
I wish you well.