Working with Databases Using JDBC
Business applications usually store data in the databases. In most of the enterprise applications, Relational Database Management Systems (RDBMSes) are used as data storage. They store the data records in tables. Each record (such as that of an employee) is represented by a table row, which consists of one or more columns or record fields (e.g., name, address, hire date). RDBMSes understand the SQL language.
The most popular RDBMSes are Oracle, DB2, Sybase, Microsoft SQL Server, and MySQL Server. All samples from this lesson will use JavaDB, which is included with your JDK installation.
Java includes two packages that contain classes required for work with DBMSes: java.sql and javax.sql. The former contains commonly used classes such as Connection, Statement, and ResultSet. The latter is used for supporting database connectivity on the server side, containing classes such as DataSource, and RowSet.
The JDBC API is not DBMS-specific — if you write a program that uses JDBC classes to retrieve/update data in Oracle, you’ll be using the same classes to work with MySQL Server or DB2. You just need the JDBC drivers from the corresponding DBMS vendor — the drivers hide their database specifics behind the same public JDBC API.
JDBC drivers either pass SQL statements from Java to a DBMS for execution or simply execute a program stored inside a DBMS (called a stored procedure). If some data has been retrieved as the result of these actions, ...