Java - JDBC

JDBC or Java Database Connectivity is an API for client-side access to a database. The database is a relational database.

When you're dealing with exceptions in a JDBC world, all JDBC operations throw a SQL exception or some subclass of it. You have to catch it or throw it. 

Terminology of JDBC

1. DriverManager - a class that interacts with the driver for creating connections
DriverManager should operate with everthing that we need in order to get simple connections.

2. DataSource - a modern class that interacts with the driver for creating connections
These DataSource classes provide a modern way of interacting with the driver itself, providing things like thread pooling and other metrics that make connecting to the database more efficient.

3. Connection - a class that the developer interacts with that manages the actual communication between the client and the server

4. Statement - the representation SQL to be excuted against the database
Statement can either be a query or an actual SQL statement that is going to modify the database.

5. ResultSet - the response from the database in a logical "tabular" form
Spin through that ResultSet to pull data out, and also to manipulate the data as we get it out.

6. PreparedStatement - an extension of statement that is used for precompiled statements(with inputs)

7. CallableStatement - an extension of PreparedStatement that references a stored procedure in the database (with inputs and outputs)

Basic Process of JDBC

Transactions

A transaction allows you to have a block of code that all executes together with a single commit.

1. Auto-commit: a function of the database driver where each statement is immediately readable by all processes once executed in the RDBMS.

2.Transaction: a series of statements that must be executed completely or not at all before other processes can read them.

3. Rollback: a mechanism by which all of the statements of a transaction are removed from the database such that it would appear to all current and future processes as this had never occurred.

JDBC vs ORM vs JPA

Why Use JDBC?

  • Technology is all about trade-offs.
  • Object relational mapping can cause just as many problems as it solves.
  • JDBC gives you control, but with a lot of manual work.
  • JDBC gives your database administrators more control, which can improve performance.

ORM Obejct Relational Mapping

  • Allows you to interact with databases through objects
  • Known as a technique, but most developers call the libary an ORM
  • Tends to reduce code, especiallly in result set mapping
  • Hibernate is a common implementation of a libary that uses ORM

JPA Java Persisttence API

  • Standard Java EE(Jakarta EE) specification for ORM
  • Hibernate is an implementation of JPA
  • Streamlines performance to standard format
  • Reduces JDBC code
  • Focus on OOP
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值