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
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

Low-Code Development: Leverage low and no code to streamline your workflow so that you can focus on higher priorities.

DZone Security Research: Tell us your top security strategies in 2024, influence our research, and enter for a chance to win $!

Launch your software development career: Dive head first into the SDLC and learn how to build high-quality software and teams.

Open Source Migration Practices and Patterns: Explore key traits of migrating open-source software and its impact on software development.

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

  • Addressing Memory Issues and Optimizing Code for Efficiency: Glide Case
  • How To Plan a (Successful) MuleSoft VPN Migration (Part II)
  • Benchmarking Java Streams
  • GBase 8a Implementation Guide: Performance Optimization
  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
Like (2)
Save
Tweet
Share
4.4K 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

ABOUT US

  • About DZone
  • Send 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: