Chapter 24. JDBC

  • Introduction to JDBC

  • Installing the Mckoi Database Software

  • Running the Example Code

  • Connecting to the Database

  • Executing SQL Statements

  • Result Sets

  • Batching SQL Statements and Transactions

  • Prepared Statements and Stored Procedures

  • Complete Example

  • Database and Result Set Metadata

  • Further Reading

  • Exercises

  • Heavy Light Relief—In Which “I” Spam Myself

In this chapter we'll build on the relational database and SQL knowledge from Chapter 23. We'll show how to use one of the several excellent open source Java-friendly relational databases available. This will let you run a database management system on your own computer and try the features in practice. The bulk of the chapter to describes JDBC, the Java library that supports access to databases. We'll walk through its classes and the way they are used. We will reuse the data from the previous chapter, involving a database holding the music preferences for a group of people. Finally, we'll show code to create and update a database, and give you the information needed to write more Java-database code yourself.

Introduction to JDBC

JDBC is made up of about two dozen Java classes in the package java.sql. The classes provide access to relational data stored in a database or other table-oriented form. JDBC works in a similar way to Microsoft's database access library (known as ODBC), but redesigned, simplified, and based on Java, not C. ODBC imposed a single library that let your Windows code interface to any database. If you are familiar with ODBC, JDBC will be a snap to learn. And even if you are not, it's still pretty straightforward. JDBC works with the largest database servers such as Oracle, DB2 and mySQL, and with the smallest desktop database systems, such as xBase files, FoxPro, and MS Access. JDBC can even access text files and Excel spreadsheets using the ODBC bridge.

JDBC classes allow the programmer to use modern database features like simultaneous connections to several databases, transaction management, pre-compiled statements with bind variables, calls to stored procedures, and access to metadata in the database dictionary. JDBC supports both static and dynamic SQL (a query or update constructed at run-time). JDBC and SQL greatly simplify deployment issues, because you can now rely on the presence of a set of vendor-independent standard Java interfaces for queries and updates to your relational database.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.32.222