DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • How To Work Effectively With JDBC in Java Scripts
  • Getting Started With HarperDB and Java: Your First "Hello, World" Integration
  • Leverage Lambdas for Cleaner Code
  • The Generic Way To Convert Between Java and PostgreSQL Enums

Trending

  • DGS GraphQL and Spring Boot
  • Building Resilient Identity Systems: Lessons from Securing Billions of Authentication Requests
  • Monolith: The Good, The Bad and The Ugly
  • AI-Driven Test Automation Techniques for Multimodal Systems
  1. DZone
  2. Data Engineering
  3. Databases
  4. JDBC Tutorial: Nice and Easy [Video]

JDBC Tutorial: Nice and Easy [Video]

Ever looked for a comprehensive intro to JDBC that is fun and entertaining at the same time? Then look no further than this video tutorial.

By 
Marco Behler user avatar
Marco Behler
DZone Core CORE ·
May. 23, 22 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
4.8K Views

Join the DZone community and get the full member experience.

Join For Free

Ever looked for a comprehensive intro to JDBC that is fun and entertaining at the same time? Then have a look at this brand-new episode of the "Marco Codes" YouTube channel: JDBC Tutorial: Nice and Easy.

In this video, you'll learn how to use JDBC, the basic API that every Java program uses to access databases. Understand what JDBC drivers are and where to get them, as well as learn how to use an embedded H2 database in addition to the usual suspects like MySQL or Postgres. Fire off SQL select, insert, update and delete statements from Java. Finally, learn about connection pools and the overall Java database framework/library landscape. By the end of the tutorial, there won't be many questions left when it comes to accessing databases with Java.

What’s in the Video?

Sooner or later, most Java applications need to talk to a database. That's what the JDBC API is for: Java Database Connectivity. Let's talk about how we're going to learn about JDBC.

First of all, you need to get a grasp of what a JDBC driver is and more specifically, how to find the correct one for your database. While you can follow along with this video with a MySQL or Postgres database, we'll take a shortcut and use an embedded H2 database for this tutorial. Why? Because it needs a special setup and can literally be added to any Java project with just a couple of lines of code.

Once you have your JDBC Driver setup, you can start connecting to databases. There are two main ways of doing that, one being the DriverManager, and the other one being DataSources. You'll first learn about the DriverManager and its pros and cons.

While trying to connect to our H2 database, we'll make sure to understand JDBC URLs, including the different vendor peculiarities and how to navigate database vendor websites.

Then it's finally time to take a look at firing off SQL queries from your tiny Java project. We'll start with the CRUD basics, which means executing SELECT, INSERT, UPDATE, and DELETE statements, and learn about the importance of PreparedStatements along the way. 

What are PreparedStatements? They are an easy and efficient way to pre-compile SQL statements on your clients, while at the same time protecting against SQL injection attacks. That's why we are going to spend some time explaining what those two concepts are.

Then, we'll look at the DataSource interface (as opposed to DriverManager), which is the more commonly used method to connect to databases. Frameworks like Spring Boot and literally all other web/database frameworks build on top of DataSources.

This finally brings us to the concept of connection pools, which also use the DataSource interface. What's a connection pool? Well, opening up database connections is a rather expensive process, and instead of opening up a new connection for every SQL statement, you could just pre-open a pool of connections that all users of your application share.

If you managed to watch the entire video, you'll be presented with some hints, tips, and resources, that will help you continue your JDBC learning journey on your own.  Check it out and let us know what you think!  

 

Database Java Database Connectivity

Opinions expressed by DZone contributors are their own.

Related

  • How To Work Effectively With JDBC in Java Scripts
  • Getting Started With HarperDB and Java: Your First "Hello, World" Integration
  • Leverage Lambdas for Cleaner Code
  • The Generic Way To Convert Between Java and PostgreSQL Enums

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!