An introduction to JDBC, JNDI and Spring JDBC with Tomcat
- Description
- Curriculum
- FAQ
- Reviews
Data Access with Spring JDBC Support using JNDI in an embedded Tomcat Server .
Course Modules :
- Course Introduction – JDBC History & Sample User Story
- Our Spring JDBC Development Environment
- Connecting to the Database
- DAO with Traditional JDBC vs Spring JDBC
- Full CRUD with Spring JDBC Template example
Why learn Spring JDBC ?
- JDBC use is widespread in large companies worldwide
- Actively maintained for 20+ years and counting
- Spring JDBC gives you a “quick win” when dealing with legacy JDBC code
Spring JDBC – Sample User Story
- As an expatriate living abroad I want access to an online database of all charities (non-profits) that operate in my “home country”.
- I want to be able to find Charities by their Tax Id
- I want to be able to search by Charity Category such as Environment or Education
- I want to be able to search by Charity Program Types
Connecting to the MariaDB with JDBC
Establishing a Connection
- Using the DriverManager Class
- Specify the database Connection URLs
Connecting to the MariaDB with Spring:
Define Spring DataSource Bean to get a DB Connection
- Specify the database properties in application.xml
- Using the MariaDB DataSource Bean Class
Connecting to the MariaDB :
Using JNDI DataSource Objects to Get a Connection
- Registering DataSource Object with Naming Service That Uses JNDI API
- Creating Instance of DataSource Class and Setting its Properties
- Using Deployed DataSource Object
Connecting to the MariaDB :
Using JNDI to Get a JDBC Connection in Embedded Tomcat
- Java Main Method to launch Embedded Tomcat
- Registering DataSource Object with JNDI API
- Using the registered JNDI DataSource Object
- Running the JAR with Maven Plugin
Connecting to the MariaDB :
Using Spring App Context to Get a JDBC Connection Tomcat
- Java Main Method to launch Embedded Tomcat
- Defining the DataSource in Spring application.xml
- Adding a context listener to web.xml
- Retrieve the Spring Data Source bean in the Servlet
Connecting to the MariaDB :
Using Spring Annotation Config in Embedded Tomcat
- Java Main Method to launch Embedded Tomcat
- Defining the DataSource in Spring Config Class
- Retrieve the Spring DataSource bean in the Servlet
-
1Course IntroductionVideo lesson
More about myself and what the course is about
-
2What is JDBC ?Video lesson
JDBC use is widespread in large companies worldwide
Actively maintained for 20+ years and counting
Spring JDBC gives you a “quick win” when dealing with legacy JDBC code
-
3Our Sample Business ProblemVideo lesson
As an expatriate living abroad, I want access to an online database of all charities (non-profits) that operate in my “home country”.
I want to be able to find Charities by their Tax Id
I want to be able to search by Charity Categories such as Environment or Education
I want to be able to search by Charity Program Types
-
4Setting up our development environmentVideo lesson
OpenJDK 11
Git & Github
IntelliJ
MariaDB
Maven 3.6
Tomcat 8.5
-
5Installing and Setting up Java 11 on Windows 10Video lesson
Download OpenJDK 11 zip
Unzip Archive
Setup JAVA_HOME environment variable
Add /bin directory to PATH
Confirm Java setup in command prompt
-
6Downloading, Installing and Setting up IntelliJVideo lesson
Download IntelliJ Ultimate Trial
Run the .exe
Confirm IntelliJ setup with OpenJDK 11
-
7Downloading, Installing and Setting up GitVideo lesson
Go to Git Downloads page - https://git-scm.com/downloads
Select and download Git for Windows 10
Run the executable (Setup)
Verify Git Bash in Windows 10
-
8Setting up our Github RepositoryVideo lesson
Prerequisite is that you have a Github account : https://github.com/join
Create a Git Repo in Github https://github.com/new
Import the Github Repository into IntelliJ
-
9Installing and setting up Maven 3 on Windows 10Video lesson
We will select the latest version of Maven: https://maven.apache.org/index.html
Download the zip file
https://maven.apache.org/download.cgi
Unzip it to our C: drive
Update our Windows Environment variables
https://maven.apache.org/install.html
Confirm Maven Setup through Command Line
-
10Maven-IntelliJ Configuration and SetupVideo lesson
Using Maven with IntelliJ
Starting with our Github created project
We will create a Maven POM Root Project Structure in IntelliJ
Look at Maven Settings in IntelliJ (.m2 & settings.xml)
We will match IntelliJ Maven with Command Line Maven
Confirm Maven Setup through Command Line
-
11Downloading and Setting up the Maria DBVideo lesson
https://downloads.mariadb.org/mariadb/+releases/
We will select the latest stable MariaDB release:
We will choose Windows 10
We will choose .MSI file download
We will follow the instruction for using MSI
Run MSI in Windows Explorer
Confirm setup through command line
-
12IntelliJ & MariaDB Setup & ConfigurationVideo lesson
Create Charity DB using MariaDB command line client
Create App User with full privileges on Charity DB
Use our POM Root from Github project in IntelliJ
Set up DB Connection in IntelliJ with App User
Create new maven module named MariaDBConnect
-
13Installing & Setting up Tomcat 8Video lesson
We will select the Tomcat 8 release downloads page:
We will choose the 64 bit zip core download
Unzip win64 zip file
Run Tomcat 8.5 from the command line
Confirm setup in the Tomcat Admin Web Page
Prerequisite is Java 7 or higher (JAVA_HOME)
Set CATALINA_HOME environment variable
Scripts: startup.bat and shutdown.bat
Set up a Tomcat Admin User through the web page Admin Install
-
14Create a Tomcat 8 run configuration in IntelliJVideo lesson
In IntelliJ
From the main menu, select Run | Edit Configurations
Click + and select Tomcat Configuration type
We will be using the local Tomcat run configuration
-
15Setting up our Charity DB with SQL Scripts in IntelliJVideo lesson
Walkthrough of running the SQL Scripts to setup Maria DB Charity FB, using the SQL Script documentation examples and IntelliJ Data Source Explorer:
Slide A
Recreate application user and Charity DB
Create Charity Table
Create Charity Category Table and relationships
Create Charity Program Table and relationships
Create Charity Associate Table and relationships
Populate Categories and Programs with scripts
Slide B
Create Charity Associate Address Table
Create Charity Associate Email Table
Create Charity Associate Phone Table
Create Charity Associate Type Table
-
16Basic JDBC Connection with DriverManager & Connection URLVideo lesson
Connecting to the MariaDB with JDBC
Establishing a Connection
Using the DriverManager Class
Specify the database Connection URLs
Create a new Connection Module (JDBC1)
Use Maven in IntelliJ
Write DriverManager App that gets JDBC Connection
Use Junit 5 Test Driver
-
17JDBC Connection with DataSource defined as Spring Bean in application.xmlVideo lesson
Use Spring Managed Driver Manager & Connection URLs
Create JDBC2 Spring DataSource Module (maven)
Define DataSource Class and its Properties in application.xml
Retrieve DataSource through Spring Classpath Context in Java Code 4. Use DataSource Object to get a Connection in the Main method.
-
18Connecting with a JNDI dataSource in Tomcat 8.5Video lesson
Connecting to the MariaDB :
Using JNDI DataSource Objects to Get a Connection
Registering DataSource Object with Naming Service That Uses JNDI API
Creating Instance of DataSource Class and Setting its Properties
Using Deployed DataSource Object
-
19Embedded Tomcat with JNDIVideo lesson
How to set up and configure an embedded Tomcat Server to connect to the MariaDB Charity DB via JNDI that we configured in our Main method Java Code
Using JNDI to Get a JDBC Connection in Embedded Tomcat
Java Main Method to launch Embedded Tomcat
Registering DataSource Object with JNDI API
Using the DataSource Object
-
20Embedded Tomcat with Spring Context and Data Source BeanVideo lesson
Using Spring App Context to Get a JDBC Connection Tomcat
Java Main Method to launch Embedded Tomcat
Defining the DataSource in Spring application.xml
Adding a context listener to web.xml
Retrieve the Spring Data Source bean in the Servlet
-
21Using Spring Annotation Config in Embedded TomcatVideo lesson
Connecting to the MariaDB :
Using Spring Annotation Config in Embedded Tomcat
Java Main Method to launch Embedded Tomcat
Defining the DataSource in Spring Config Class
Retrieve the Spring DataSource bean in the Servlet
-
22Create DAO with traditional direct JDBC using Spring Config with XML BeansVideo lesson
Learn about problems with using Direct JDBC:
Setting up the Data Source
Using the DAO Pattern
Implementing the DAO with direct JDBC
Using Spring App Context to Get a JDBC Connection
Tomcat Java Main Method to launch Embedded Tomcat
Defining the DataSource in Spring application.xml Adding a context listener to web.xml
Retrieve the Spring Data Source bean in the Servlet
-
23Create DAO with traditional JDBC Spring Config AnnotationsVideo lesson
Setting up the Connection Pool Data Source
Using the DAO Pattern
Using DAO and DataSource as Spring Beans
Implementing the DAO with direct transactional JDBC
Update the DAO with JDBC for full CRUD capability, using Connection Pooling to get the Data Source and expanding the Charity Object Model to include its Category Types
-
24Using a DAO with Spring JdbcDaoSupportVideo lesson
Using a DAO with Spring JdbcDaoSupport to insert a new Charity and retrieve the Charity from the database
Using Spring JdbcDaoSupport abstract class : (JDBCTemplate)
Setting up the Data Source
Extending the DAO Pattern
Using DAO and DataSource as Spring Beans
Using DAO with JdbcDaoSupport
-
25Using Spring JdbcDaoSupport with TransactionsVideo lesson
Using Spring JdbcDaoSupport with Transactions :
Setting up the Data Source
Extending the DAO Pattern with JdbcDaoSupport
Using DAO and DataSource as Spring Beans
Using DAO with JdbcDaoSupport
-
26Using a DAO with Spring JdbcDaoSupport to do transactional CRUDVideo lesson
Setting up the Data Source
Extending the DAO Pattern
Using DAO and DataSource as Spring Beans
Using DAO with JdbcDaoSupport
-
27Using Spring Boot with Spring JDBC and Embedded TomcatVideo lesson
Using Spring Spring Boot :
All components come prepackaged
Using DataSource as Spring Bean
Using the DAO Implementation as Spring Components
Using the Service Layer as Components
Adding a Controller and Template Pages
External Links May Contain Affiliate Links read more