Java & PostgreSQL - using them together?

Hi, I can understand Java and PostgreSQL in isolation. However, I struggle with understanding how I can combine the two. Both the basics of how to do it (I heard something called JDBC, and also Doobie but perhaps thats only Scala, but didn't learn it so far), but also how to know WHEN to use the SQL and when to write Java code. For example, I might want to connect my Java program to a database that stores all the users of a bank account. I would like to be able to fetch the users balance at a given date, but it would be horribly slow if all of it was done in Java, so we would have to create some kind of database in PostgreSQL. This is an easy example, but in other cases I don't have any real guidestick (syntactically, algorithmatically, and architecture/system design wise) to know when to write Java code and when to write PostgreSQL code, and how to combine them. Any course or material is appreciated. For example if you know a good udemy course that teaches this or something else (perhaps neetcode? but maybe he doesnt teach postgreSQL).
51 Replies
JavaBot
JavaBot13mo ago
This post has been reserved for your question.
Hey @Steadhaven! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Steadhaven
SteadhavenOP13mo ago
Yes that much is clear, but I was looking for some sort of course that goes through JDBC/JPA for Java & PostgreSQL. My difficulty is to know how to properly combine both of them to make a performant program. I already know PostgreSQL and Java in isolation, and I could probably learn how to use JDBC/JPA to connect them in no time. But how do I know if I should write some Queries to get the data, or some pure java code? And how do I actually write that code properly inside Java (and not just SQL queries in Pgadmin)? Hopefully some beginner course exist on this :) If I were to write pure java code that would fetch all of an accounts bank transactions from the database it would be really inefficient. A better way would be to write some SQL query inside the java code, that simply executes select * from tablename (simplification). Of course, this is an easy case, but I hope you understand that I am looking for better understanding of how to write programs that is performant and scalable. I.e. I am confused on the actual implementation logic, and need some basic course that goes through this :) something more than isolated potsgresql, and isolated java course, but a combination of the two.
tjoener
tjoener13mo ago
I mean it depends, if you want to go for full performance, you can go for raw JDBC, but it will be quite painful 😄 There's layers on top that map your tables to objects, like hibernate etc, that are still pretty fast, but it all depends on the use case ofc I've done some raw imports of stack overflow dumps, and I do those in pure JDBC, with some code I wrote around it, but it's quite a handful. Then I'm actually limited by the database
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
tjoener
tjoener13mo ago
spring-jpa begs to differ? 😄 "magic"
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
tjoener
tjoener13mo ago
findByName(String name) Yeah, but I don't have to write SQL
Steadhaven
SteadhavenOP13mo ago
(sorry for not being concise and bad at formulating my confusion but its because this area is totally unclear to me right now :p ) I am looking for something very basic, like super fundamental and beginner level, that somehow teaches me how to write actual code (whatever that code is, like I don't know "you cannot write pure java code that would fetch...", I am a step lower in that in my understanding, and don't know JDBC/JPA/etc). I can write some simple pure java programs, and some simple pure database in postgresql with some isolated queries there. I didn't reach further than this in my understanding. Now when I want to make a simple banking program (nothing fancy) in Java, i would have to store the data in a database whenever a user interacts with a simple business logic inside my java program. Do you know if there exist some udemy or other course that teaches me how to combine a database with java, and how to know when to write what and how to do it in a performant way? (probably 99% of what I wrote is a misunderstanding or wrong angle, but I hope you understand what sort of knowledge/course I am looking for)
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
tjoener
tjoener13mo ago
It depends, do you WANT to write SQL manually, or are you more adventurous and looking for a slightly more convenient way of accessing the database?
Steadhaven
SteadhavenOP13mo ago
I am looking for the industry standard of what is needed in the real world :) to be employable
tjoener
tjoener13mo ago
ah, that would be the spring framework With hibernate
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Steadhaven
SteadhavenOP13mo ago
Ok thanks so I will have to google "java intro to jdbc" and find topics on this :)
JavaBot
JavaBot13mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Steadhaven
SteadhavenOP13mo ago
nope why?
tjoener
tjoener13mo ago
Baeldung
Learn JPA & Hibernate | Baeldung
A series of tutorials on the core features of JPA and Hibernate.
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
tjoener
tjoener13mo ago
Baeldung has good java stuff
Steadhaven
SteadhavenOP13mo ago
is it too formal? :) haha
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Steadhaven
SteadhavenOP13mo ago
danish and english
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Steadhaven
SteadhavenOP13mo ago
So I will be best served to learn the Spring framework with JPA hibernate to be a better fit for the industry
tjoener
tjoener13mo ago
Last 7 jobs I had were in those two technologies spring-boot more specifically
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
tjoener
tjoener13mo ago
JPA is a rabbithole, and it is DEEP
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Steadhaven
SteadhavenOP13mo ago
I often hear people speak about Spring and Spring boot, and then JPA and JDBC
tjoener
tjoener13mo ago
yeah
Steadhaven
SteadhavenOP13mo ago
so if I know Java and PostgreSQL at a fundamental level, a logical next step would be to learn Spring (not spring boot**) with JPA (not JDBC) right?
tjoener
tjoener13mo ago
spring boot, which is a framework
Steadhaven
SteadhavenOP13mo ago
Ah Spring boot and JPA
tjoener
tjoener13mo ago
Of those 7 I've had one that uses "base" spring The 6 others were boot
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Steadhaven
SteadhavenOP13mo ago
Ok I will learn about JDBC, then "Spring Boot + JPA"
tjoener
tjoener13mo ago
Entity here, repository there, 90% of your database needs covered
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Steadhaven
SteadhavenOP13mo ago
Thanks
JavaBot
JavaBot13mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
tjoener
tjoener13mo ago
They finally figured out microservices are a sham 😄
Steadhaven
SteadhavenOP13mo ago
Here's my plan for learning: 1. Refresh Data Structures & Algorithms on Java (already doing right now) 2. Refresh PostgreSQL 3. JDBC 4. dependency injection 5. Spring Boot 6. JPA Hibernate
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
tjoener
tjoener13mo ago
maybe stick jdbc and hibernate a bit closer together but yeah
Steadhaven
SteadhavenOP13mo ago
Oh true they are connect haha 1. Refresh Data Structures & Algorithms on Java (already doing right now) 2. Refresh PostgreSQL 3. dependency injection 4. Spring Boot 5. JDBC 6. JPA Hibernate
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Steadhaven
SteadhavenOP13mo ago
Ty for the tiops and I will subscribe to laur spilca
JavaBot
JavaBot13mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?