JDBC Tutorials

jdbc tutorials

In this detailed Resource page, we feature an abundance of JDBC Tutorials!

Java Database Connectivity (JDBC) is an application programming interface (API) for the programming language Java, which defines how a client may access a database. It is a Java-based data access technology used for Java database connectivity. It is part of the Java Standard Edition platform, from Oracle Corporation. It provides methods to query and update data in a database, and is oriented towards relational databases. A JDBC-to-ODBC bridge enables connections to any ODBC-accessible data source in the Java virtual machine (JVM) host environment.

History and implementation

Sun Microsystems released JDBC as part of Java Development Kit (JDK) 1.1 on February 19, 1997. Since then it has been part of the Java Platform, Standard Edition (Java SE).

The JDBC classes are contained in the Java package java.sql and javax.sql.

Starting with version 3.1, JDBC has been developed under the Java Community Process. JSR 54 specifies JDBC 3.0 (included in J2SE 1.4), JSR 114 specifies the JDBC Rowset additions, and JSR 221 is the specification of JDBC 4.0 (included in Java SE 6). JDBC 4.1, is specified by a maintenance release 1 of JSR 221 and is included in Java SE 7. JDBC 4.2, is specified by a maintenance release 2 of JSR 221 and is included in Java SE 8. The latest version, JDBC 4.3, is specified by a maintenance release 3 of JSR 221 and is included in Java SE 9.

Functionality

JDBC allows multiple implementations to exist and be used by the same application. The API provides a mechanism for dynamically loading the correct Java packages and registering them with the JDBC Driver Manager. The Driver Manager is used as a connection factory for creating JDBC connections.

JDBC connections support creating and executing statements. These may be update statements such as SQL’s CREATE, INSERT, UPDATE and DELETE, or they may be query statements such as SELECT. Additionally, stored procedures may be invoked through a JDBC connection. JDBC represents statements using one of the following classes:

  • Statement – the statement is sent to the database server each and every time.
  • PreparedStatement – the statement is cached and then the execution path is pre-determined on the database server allowing it to be executed multiple times in an efficient manner.
  • CallableStatement – used for executing stored procedures on the database.

Update statements such as INSERT, UPDATE and DELETE return an update count that indicates how many rows were affected in the database. These statements do not return any other information.

Query statements return a JDBC row result set. The row result set is used to walk over the result set. Individual columns in a row are retrieved either by name or by column number. There may be any number of rows in the result set. The row result set has metadata that describes the names of the columns and their types.

Note
If you wish to build up your Java Database Connectivity knowledge first, check out our JDBC Tutorial – The ULTIMATE Guide.

JDBC Tutorials – Getting Started

Simple examples based on the Java Database Connectivity

  • JDBC Best Practices Tutorial
    Hello, in this tutorial we will learn some Java Database Connectivity (JDBC) best practices that Java programmer should follow while writing JDBC code. JDBC API is used to connect and interact with the relational databases to perform CREATE, READ, UPDATE, DELETE (commonly known as CRUD) operations.
  • Get JDBC Connection parameters
    With this example we are going to demonstrate how to get the JDBC Connection parameters.
  • Java JDBC MSSQL Connection Example
    Java Database Connectivity (JDBC) is a Java-based data access technology that defines how a client may access a database. It provides methods for querying and updating the data in a database. The JDBC classes are contained in the Java package i.e. java.sql and javax.sql.
  • JDBC Connection Pool Example
    Connection pooling is a mechanism to create and maintain a collection of JDBC connection objects. The primary objective of maintaining the pool of connection object is to leverage re-usability and improve the overall performance of the app. In this article, we will try to show how connection pooling mechanism can be applied to a Java app.
  • JDBC Query Builder Tutorial
    In this JDBC Query Builder example, we will see how to achieve dynamic SQL Query Builder phenomenon by using the open-source Sqlbuilder library. But before moving ahead let’s take a look and understand JDBC and Sqlbuilder library.
  • JDBC DDL Example
    Data Definition Language (DDL) is a unique set of SQL commands that lets you manipulate the structure of the database. In this article, we will try to show how the JDBC DDL mechanism can be applied to a Java application.
  • JDBC Create Table example
    This article presents a simple example of creating a database table. We will be using the JDBC (Java DataBase Connectivity) API to connect to a relational database and execute a SQL query to create a table using the Statement object.
  • JDBC Driver Types Example
    In this example we will review different JDBC Driver Types. We will write a simple Java application to demonstrate how to use JDBC connectivity steps to access an SQLite database.JDBC stands for Java DataBase Connectivity.
  • JDBC Servlet Example
    In this example, we will see how to make use of JDBC from a servlet to access database and read data from table. We will use MySQL as the database and MySQL Workbench as the client for database to prepare the data. However this example does not cover installation of MySQL and MySQL Workbench.
  • JDBC DatabaseMetaData Example
    In this example will talk about how to get the Database’s Metadata and what is the usefulness of that information for our development, through the Java API JDBC java.sql.DatabaseMetaData.

JDBC Tutorials – Functions

Learn the most famous functionalities and operations of the JDBC

Jdbc Transaction

  • JDBC Transaction Rollback Example
    In this example will talk about how to perform rollback in JDBC transactions.When we are making changes in the database through a java.sql.Connection, it’s necessary prevent it form going to an inconsistent state, in case of an exception for example. So how do we do that? There are some key steps.
  • JDBC Transaction Management Example
    In this post, we want to talk about JDBC Transactions and how we can manage the operations in a database.The most popular DBMS like MySQL and Oracle have by default the option autocommit enabled, it means immediately after any DML Operation saves the changes and makes them visible to all users.
  • JDBC Nested Transactions Example
    A nested transaction is used to provide a transactional guarantee for a subset of operations performed within the scope of a larger transaction. Doing this allows us to commit and abort the subset of operations independently of the larger transaction.

Jdbc Batch

  • JDBC Batch Insert Example
    In this article we are going to present a simple example of using JDBC Batch for doing bulk inserts into a relational database. As stated in a previous article, the Batch operation exposed in JDBC (Java DataBase Connectivity API) helps to bundle together a group of operations and execute them as a single unit.
  • JDBC Batch Update Example
    This article presents a simple example of performing JDBC Batch Update. It assumes that the reader is familiar with the JDBC (Java DataBase Connectivity) API which is just one of the tools in Java for connecting to a database from a client. The API provides several simple methods for querying and updating data in a database.
  • JDBC Batch Processing Example
    In this example, we will see how we can use Batch Processing in Java Database Connectivity(i.e.JDBC).When multiple inserts are to be made to the table in a database, the trivial way is to execute a query per record.

Jbdc ResultSet

  • Java JDBC ResultSet Example
    With this example we are going to demonstrate how to use ResultSet in order to get and manipulate data from a database. ResultSet is essentially a table, which contains all the information that should be returned from a specific query, as well as some essential metadata. For the purposes of this article, we are going to assume that the database in use is MySQL, since it is one of the most well-known and beginner friendly databases out there.
  • JDBC ResultSetExtractor Example
    Spring provides a simplification in handling database access with the Spring JDBC Template. The org.springframework.jdbc.core.ResultSetExtractor interface is a callback interface used by JdbcTemplate’s query methods. Implementations of this interface perform the actual work of extracting results from an SQL ResultSet object.In this article, we will try to show how the ResultSetExtractor mechanism can be applied to a Java application.

JDBC Tutorials – Integrations

Learn how to use JDBC with other frameworks

Spring

  • Jdbc Example For Beginners
    In this example we will learn how to use JDBC shipped with Java SE. The purpose of JDBC is to make possible interaction with any database in a generic way.We will see how to connect to a database and how to manipulate data stored in it. We will create a register which stores personal contact data like email and phone number.
  • Spring RowMapper Example
    Spring Jdbc framework provides a mechanism to fetch the records from a database using the query() method. This tutorial will explore the Spring Jdbc connectivity to fetch the records from the relational database.
  • Spring Integration Jdbc RowMapper Example
    The JDBC inbound channel adapter’s basic function is to execute a SQL query, extract the data and pass the result set encapsulated in the form of a Message onto the local channels. You can read more about this in my example on JDBC Inbound Channel Adapter.
  • Jdbc Named Parameters Example with Spring NamedParameterJdbcTemplate
    In this example we will present the usage of Spring NamedParameterJdbcTemplate.
  • Spring Transaction Management Example with JDBC Example
    In this article, I will show you an example of spring transaction management using JDBC. Let me first touch base on what is transaction and how spring facilitates transaction management.
  • Spring JdbcTemplate Example
    In this post, we feature a comprehensive Example on Spring JdbcTemplate. When we need to interface with databases the Spring JDBC framework provides solutions to all the low-level details, like open/close a connection, prepare and execute SQL statements, process exceptions and handle transactions.
  • Spring JdbcTemplate CRUD Operations Tutorial
    Spring JdbcTemplate is a powerful mechanism to connect to the database and execute SQL queries. In this tutorial, we will discuss the Spring JdbcTemplate and we will cover all the CRUD operations.
  • Create Data Source for JdbcTemplate
    This is an example of how to create a Datasource for the JdbcTemplate class provided by the Spring Framework. The DataSource class is a utility class that provides connection to the database.
  • Insert record in database with JdbcTemplate
    This is an example of how to insert a record to the database using the JdbcTemplate class provided by the Spring Framework.
  • Update records in database with JdbcTemplate
    In this example we shall show you how to update records in a database using the JdbcTemplate Class provided by the Spring Framework.
  • Select records from database with JdbcTemplate
    With this example we are going to demonstrate how to select records from a database using the JdbcTemplate class provided by the Spring Framework.
  • Delete records in database with JdbcTemplate
    With this example we are going to demonstrate how to delete records in a database, using the JdbcTemplate class provided by the Spring Framework.
  • Spring MVC Pagination Example
    In this tutorial, we will show how to implement the pagination functionality in the spring mvc framework.

Oracle

  • Using the JDBC Insert Features in Oracle
    In this article I will show an example of how to use the JDBC bulk insert features supported by Oracle — and which are specific to Oracle.
  • JDBC with Oracle Thin Driver Example
    Java Database Connectivity (JDBC) is a Java-based data access technology that defines how a client may access a database. It provides methods for querying and updating the data in a database. The JDBC classes are contained in the Java package i.e. java.sql and javax.sql.
  • JDBC CallableStatement with Oracle Stored Procedure Example Tutorial
    In this Article We will learn how to use JDBC CallableStatement along with Stored Procedures, Cursors, STRUCT etc. For this Example we have used Oracle Database. We will start by using CallableStatement with IN and OUT parameters.

PostgreSQL

  • Java JDBC PostgreSQL Connection Example
    This article is a Java JDBC PostgreSQL Connection Example. PostgreSQL is an object-relational database management system. It’s one of the most popular databases used in the world. This article will show you how Java connects to it using JDBC.
  • Java PostgreSQL Example
    In this article I will discuss about PostgreSQL database and how to use it through Java code. PostgreSQL, or simply Postgres, is an Object-Relational Database Management System (ORDBMS).

Tomcat

  • Tomcat connection pool configuration example
    In this example we will discuss Apache Tomcat Servlet/JSP container’s connection pull configuration via JNDI resources. The connection pool we will look at is javax.sql.DataSource, which is a JDBC API for getting a connection instance to a database. In this example we will discuss setting a global DataSource for MySQL database.
  • Using Tomcat JDBC Connection Pool in Standalone Java Application
    When using a JDBC connection pool in standalone Java applications that require data access, most of the developers will use either commons-dbcp or c3p0. In this tutorial, we will discuss using the JDBC connection pool in Apache Tomcat web container in standalone Java applications.

Ohter

  • JDBC HSQLDB Tutorial
    In this tutorial we will review HSQLDB basics. Then we will write a simple Java application to demonstrate how to access and interact with an HSQLDB database using JDBC.
  • JDBC Connection Strings for Popular RDBMS
    In this article, we are presenting a consolidation of the different Connection Strings that are to be used for connecting to some of the most popular RDBMS (Relational DataBase Management Systems).

[undereg]

Back to top button