Home » Core Java » sql

sql

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. 1. Introduction In this article, we will describe how to write the application code to establish ...

Read More »

JDBC Query Builder Tutorial

Handling SQL within a Java application can be tricky. For one thing, Java does not support multi-line string constants, so developers can end up with code that looks like this:                   Sample Code String sql_query = "select *" + "from user_table" + "where name like 'Fred%'"; This code is not just ugly ...

Read More »

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. This operation is theoretically possible, however, in JDBC 3.0 we can’t achieve this as easily as the definition looks. In ...

Read More »

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. 1. Introduction In this JDBC Oracle connectivity example, we will see how to setup a JDBC ...

Read More »

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

Read More »

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. 1. Introduction It might sound like its own programming language, but Data Definition Language (DDL) is really a way to ...

Read More »

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 application. In this article, we will try to show how connection pooling mechanism can be applied to a Java application. 1. Introduction JDBC stands ...

Read More »

JDBC Create Table example

1. Introduction 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. Note that one could use any of the methods offered by the Statement object viz. execute(String sql), executeQuery(String ...

Read More »

JDBC Batch Insert Example

1. Introduction 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. This helps to avoid ...

Read More »

JDBC Batch Update Example

1. Introduction 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. Consider a ...

Read More »