What_is_JDBC[1].pdf - What is JDBC Introduction to Java...

This preview shows page 1 - 4 out of 12 pages.

What is JDBC? Introduction to Java Database Connectivity Get to know Java's low-level API for making database connections and handling SQL queries and responses JDBC (Java Database Connectivity) is the Java API that manages connecting to a database, issuing queries and commands, and handling result sets obtained from the database. Released as part of JDK 1.1 in 1997, JDBC was one of the first components developed for the Java persistence layer. JDBC was initially conceived as a client-side API, enabling a Java client to interact with a data source. That changed with JDCB 2.0, which included an optional package supporting server-side JDBC connections. Every new JDBC release since then has featured updates to both the client- side package ( java.sql ) and the server-side package ( javax.sql ). JDBC 4.3, the most current version as of this writing, was released as part of Java SE 9 in September 2017. This article presents an overview of JDBC, followed by a hands-on introduction to using the JDBC API to connect a Java client with SQLite, a lightweight relational database. [ How JDBC works Developed as an alternative to the C-based ODBC (Open Database Connectivity) API, JDBC offers a programming-level interface that handles the mechanics of Java applications communicating with a database or RDBMS. The JDBC interface consists of two layers: 1. The JDBC API supports communication between the Java application and the JDBC manager. 2. The JDBC driver supports communication between the JDBC manager and the database driver. JDBC is the common API that your application code interacts with. Beneath that is the JDBC- compliant driver for the database you are using. Figure 1 is an architectural overview of JDBC in the Java persistence layer.
Using JDBC to connect to a database One of the fortunate facts of programming in the Java ecosystem is that you will likely find a stable JDBC database connector for whatever database you choose. In this tutorial we'll use SQLite to get to know JDBC, mainly because it's so easy to use. The steps for connecting to a database with JDBC are as follows: 1. Install or locate the database you want to access. 2. Include the JDBC library. 3. Ensure the JDBC driver you need is on your classpath. 4. Use the JDBC library to obtain a connection to the database. 5. Use the connection to issue SQL commands. 6. Close the connection when you're finished. We'll go through these steps together. Finding a JDBC driver To find a driver for the database you want to use, simply do a web search for your database and JDBC. For instance, typing in " mysql jdbc driver " will turn up a driver for MySQL. I challenge you to find a Java-compatible database without a JDBC driver! Step 1. Download and install SQLite SQLite is a very compact database. It isn't intended for production use, but is a great choice for quickly trying things out. SQLite uses a file as its functional database, without requiring any service or daemon installations.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture