SlideShare a Scribd company logo
JDBC
JPA
Spring Data
The JDBC API makes it possible to
do three things:
• Establish a connection with a
database or access any tabular
data source
• Send SQL statements
• Process the results
JDBC (1)
Connection conn = null;
Statement stmt = null;
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost/EMP",
"username", "password");
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT id, first FROM Employees");
while (rs.next()) {
System.out.println("ID: " + rs.getInt("id")
+ ", First: " + rs.getString("first"));
}
rs.close();
stmt.close();
conn.close();
JDBC (2)
JPA(1)
Includes:
• the API itself, defined in the
javax.persistence package
• the Java Persistence Query
Language (JPQL)
• object/relational metadata
DAO -> Persistance
JPA(2)
@Entity
@Table(name = "orders")
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private long id;
@Column(name = "date")
private Date date;
@ManyToOne
@JoinColumn(name = "product_id")
private Product product;
}
JPA(3)
Product product = new Product();
Order order = new Order();
order.setProduct(product);
entityManager.persist(product);
entityManager.persist(order);
Product dbProduct = entityManager.find(Product.class, product.getId());
String name = "InitialName";
String query = "SELECT p FROM Product p WHERE p.name LIKE
:productName";
Product product = entityManager.createQuery(query, Product.class)
.setParameter("productName", name)
.getSingleResult();
Spring Data
CrudRepository PagingAndSortingRepository
JPARepository
Spring Data
JPA
CassandraRepository
Spring Data
Cassandra
MongoRepository
Spring Data
MongoDB
Spring Data
...
JPA
JDBC
DataStax Java Driver Mongo Java Driver
RDBMS Cassandra MongoDB
Spring Data(1)
Spring Data(2)
public interface CrudRepository<T, ID extends Serializable>
extends Repository<T, ID> {
<S extends T> S save(S entity);
T findOne(ID primaryKey);
Iterable<T> findAll();
Long count();
void delete(T entity);
boolean exists(ID primaryKey);
// … more functionality omitted.
}
Spring Data(3)
public interface PersonRepository extends Repository<User, Long> { … }
List<Person> findByLastname(String lastname);
public class SomeClient {
@Autowired
private PersonRepository repository;
public void doSomething() {
List<Person> persons = repository.findByLastname("Matthews");
}
}
Spring Data(4)
interface UserRepositoryCustom {
public void someCustomMethod(User user);
}
class UserRepositoryImpl implements UserRepositoryCustom {
public void someCustomMethod(User user) {
// Your custom implementation
}
}
public interface UserRepository extends CrudRepository<User, Long>,
UserRepositoryCustom {
// Declare query methods here
}
Spring Data(5)
Spring Data JPA
@Query("select u from User u where u.emailAddress = ?1")
User findByEmailAddress(String emailAddress);
@Query("select u from User u")
Stream<User> findAllByCustomQueryAndStream();
Spring Data REST
Expose DB through REST (JSON in HAL notation)

More Related Content

PPTX
Spring data jpa
PPTX
Spring Boot and REST API
PPT
Spring Core
PDF
Spring boot introduction
PPTX
Spring boot
 
PPTX
React js
PPT
JDBC
PDF
Spring Data JPA from 0-100 in 60 minutes
Spring data jpa
Spring Boot and REST API
Spring Core
Spring boot introduction
Spring boot
 
React js
JDBC
Spring Data JPA from 0-100 in 60 minutes

What's hot (20)

PPTX
Spring boot Introduction
PDF
Spring Framework - Core
PDF
Spring Data JPA
PDF
Spring Data JPA
PPTX
Spring Web MVC
PPTX
Easy data-with-spring-data-jpa
PPT
Spring Boot in Action
PDF
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
PPTX
JavaScript Basic
PDF
Spring Batch
PPS
JUnit Presentation
PDF
An Introduction to Redux
PDF
Spring boot jpa
PPT
Java servlets
PDF
Spring Framework - MVC
PDF
Clean code
PPTX
Spring Framework
 
PDF
REST APIs with Spring
PPT
JDBC – Java Database Connectivity
PPT
Spring boot Introduction
Spring Framework - Core
Spring Data JPA
Spring Data JPA
Spring Web MVC
Easy data-with-spring-data-jpa
Spring Boot in Action
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
JavaScript Basic
Spring Batch
JUnit Presentation
An Introduction to Redux
Spring boot jpa
Java servlets
Spring Framework - MVC
Clean code
Spring Framework
 
REST APIs with Spring
JDBC – Java Database Connectivity
Ad

Viewers also liked (20)

PPTX
Spring Data - Intro (Odessa Java TechTalks)
PDF
Spring Data Jpa
PDF
An introduction into Spring Data
PPT
Spring + JPA + DAO Step by Step
PDF
Spring Data Jpa
PPT
Java Persistence API (JPA) - A Brief Overview
ODP
Spring Data in 10 minutes
PPTX
Thinking Beyond ORM in JPA
PDF
Hibernate using jpa
PDF
Lazy vs. Eager Loading Strategies in JPA 2.1
DOCX
Colloquium Report
PDF
Secure Authentication and Session Management in Java EE
PPT
Spring Boot. Boot up your development
PDF
Persistance avec JPA
 
PDF
Jpa with spring data
PDF
Java persistence api 2.1
PPTX
JPA For Beginner's
PDF
Second Level Cache in JPA Explained
PDF
JPA - Beyond copy-paste
PPTX
Spring.Boot up your development
Spring Data - Intro (Odessa Java TechTalks)
Spring Data Jpa
An introduction into Spring Data
Spring + JPA + DAO Step by Step
Spring Data Jpa
Java Persistence API (JPA) - A Brief Overview
Spring Data in 10 minutes
Thinking Beyond ORM in JPA
Hibernate using jpa
Lazy vs. Eager Loading Strategies in JPA 2.1
Colloquium Report
Secure Authentication and Session Management in Java EE
Spring Boot. Boot up your development
Persistance avec JPA
 
Jpa with spring data
Java persistence api 2.1
JPA For Beginner's
Second Level Cache in JPA Explained
JPA - Beyond copy-paste
Spring.Boot up your development
Ad

Similar to JDBC - JPA - Spring Data (20)

PPTX
Advance java session 5
PPT
YDP_API&MS_UNIT_hiii detail notes to understand api.ppt
PPT
YDP_API&MS_UNIT_IIIii8iiiiiiiii8iiii.ppt
PPTX
JDBC PPT(4).pptx java Database Connectivity
PDF
Introduction to JPA and Hibernate including examples
PPTX
PDF
JDBC, What Is It Good For?
PDF
springdatajpa-up.pdf
PDF
Spring db-access mod03
PPTX
Jpa 2.1 Application Development
PPT
JDBC.ppt
PDF
Understanding
PDF
Using the latest Java Persistence API 2.0 features
PPT
Java persistence api
PDF
Introduction to JDBC and JDBC Drivers
 
ODP
Polyglot persistence with Spring Data
PDF
10 jdbc
PDF
10 jdbc
PDF
IRJET- Review on Java Database Connectivity
Advance java session 5
YDP_API&MS_UNIT_hiii detail notes to understand api.ppt
YDP_API&MS_UNIT_IIIii8iiiiiiiii8iiii.ppt
JDBC PPT(4).pptx java Database Connectivity
Introduction to JPA and Hibernate including examples
JDBC, What Is It Good For?
springdatajpa-up.pdf
Spring db-access mod03
Jpa 2.1 Application Development
JDBC.ppt
Understanding
Using the latest Java Persistence API 2.0 features
Java persistence api
Introduction to JDBC and JDBC Drivers
 
Polyglot persistence with Spring Data
10 jdbc
10 jdbc
IRJET- Review on Java Database Connectivity

Recently uploaded (20)

PPTX
assetexplorer- product-overview - presentation
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PDF
Complete Guide to Website Development in Malaysia for SMEs
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Patient Appointment Booking in Odoo with online payment
PDF
Download FL Studio Crack Latest version 2025 ?
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by AndrĂŠ Kraus
PDF
Cost to Outsource Software Development in 2025
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
medical staffing services at VALiNTRY
PPTX
L1 - Introduction to python Backend.pptx
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
17 Powerful Integrations Your Next-Gen MLM Software Needs
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Salesforce Agentforce AI Implementation.pdf
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
assetexplorer- product-overview - presentation
Oracle Fusion HCM Cloud Demo for Beginners
Complete Guide to Website Development in Malaysia for SMEs
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Patient Appointment Booking in Odoo with online payment
Download FL Studio Crack Latest version 2025 ?
T3DD25 TYPO3 Content Blocks - Deep Dive by AndrĂŠ Kraus
Cost to Outsource Software Development in 2025
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Odoo Companies in India – Driving Business Transformation.pdf
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
medical staffing services at VALiNTRY
L1 - Introduction to python Backend.pptx
Navsoft: AI-Powered Business Solutions & Custom Software Development
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
17 Powerful Integrations Your Next-Gen MLM Software Needs
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Salesforce Agentforce AI Implementation.pdf
wealthsignaloriginal-com-DS-text-... (1).pdf

JDBC - JPA - Spring Data

  • 2. The JDBC API makes it possible to do three things: • Establish a connection with a database or access any tabular data source • Send SQL statements • Process the results JDBC (1)
  • 3. Connection conn = null; Statement stmt = null; Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection("jdbc:mysql://localhost/EMP", "username", "password"); stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT id, first FROM Employees"); while (rs.next()) { System.out.println("ID: " + rs.getInt("id") + ", First: " + rs.getString("first")); } rs.close(); stmt.close(); conn.close(); JDBC (2)
  • 4. JPA(1) Includes: • the API itself, defined in the javax.persistence package • the Java Persistence Query Language (JPQL) • object/relational metadata DAO -> Persistance
  • 5. JPA(2) @Entity @Table(name = "orders") public class Order { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id") private long id; @Column(name = "date") private Date date; @ManyToOne @JoinColumn(name = "product_id") private Product product; }
  • 6. JPA(3) Product product = new Product(); Order order = new Order(); order.setProduct(product); entityManager.persist(product); entityManager.persist(order); Product dbProduct = entityManager.find(Product.class, product.getId()); String name = "InitialName"; String query = "SELECT p FROM Product p WHERE p.name LIKE :productName"; Product product = entityManager.createQuery(query, Product.class) .setParameter("productName", name) .getSingleResult();
  • 7. Spring Data CrudRepository PagingAndSortingRepository JPARepository Spring Data JPA CassandraRepository Spring Data Cassandra MongoRepository Spring Data MongoDB Spring Data ... JPA JDBC DataStax Java Driver Mongo Java Driver RDBMS Cassandra MongoDB Spring Data(1)
  • 8. Spring Data(2) public interface CrudRepository<T, ID extends Serializable> extends Repository<T, ID> { <S extends T> S save(S entity); T findOne(ID primaryKey); Iterable<T> findAll(); Long count(); void delete(T entity); boolean exists(ID primaryKey); // … more functionality omitted. }
  • 9. Spring Data(3) public interface PersonRepository extends Repository<User, Long> { … } List<Person> findByLastname(String lastname); public class SomeClient { @Autowired private PersonRepository repository; public void doSomething() { List<Person> persons = repository.findByLastname("Matthews"); } }
  • 10. Spring Data(4) interface UserRepositoryCustom { public void someCustomMethod(User user); } class UserRepositoryImpl implements UserRepositoryCustom { public void someCustomMethod(User user) { // Your custom implementation } } public interface UserRepository extends CrudRepository<User, Long>, UserRepositoryCustom { // Declare query methods here }
  • 11. Spring Data(5) Spring Data JPA @Query("select u from User u where u.emailAddress = ?1") User findByEmailAddress(String emailAddress); @Query("select u from User u") Stream<User> findAllByCustomQueryAndStream(); Spring Data REST Expose DB through REST (JSON in HAL notation)