Preview JDBC Tutorial

Preview JDBC Tutorial

About the Tutorial JDBC API is a Java API that can access any kind of tabular data, especially data stored in a Relational Database. JDBC works with Java on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. Audience This tutorial is designed for Java programmers who would like to understand the JDBC framework in detail along with its architecture and actual usage. Prerequisites Before proceeding with this tutorial, you should have a good understanding of Java programming language. As you are going to deal with RDBMS, you should have prior exposure to SQL and Database concepts. Copyright & Disclaimer Copyright 2015 by Tutorials Point (I) Pvt. Ltd. All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish any contents or a part of contents of this e-book in any manner without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at [email protected] i Table of Contents About the Tutorial ..................................................................................................................................... i Audience .................................................................................................................................................... i Prerequisites .............................................................................................................................................. i Copyright & Disclaimer .............................................................................................................................. i Table of Contents ...................................................................................................................................... ii 1. INTRODUCTION ..................................................................................................................... 1 What is JDBC? ........................................................................................................................................... 1 Pre-Requisite ............................................................................................................................................ 1 JDBC Architecture ..................................................................................................................................... 1 Common JDBC Components ...................................................................................................................... 2 The JDBC 4.0 Packages .............................................................................................................................. 3 2. SQL SYNTAX .......................................................................................................................... 4 Create Database ....................................................................................................................................... 4 Drop Database .......................................................................................................................................... 4 Create Table .............................................................................................................................................. 4 Drop Table ................................................................................................................................................ 5 INSERT Data .............................................................................................................................................. 5 SELECT Data .............................................................................................................................................. 5 UPDATE Data ............................................................................................................................................ 6 DELETE Data .............................................................................................................................................. 6 3. ENVIRONMENT ..................................................................................................................... 8 Install Java ................................................................................................................................................ 8 Install Database ........................................................................................................................................ 8 Install Database Drivers ............................................................................................................................ 9 ii Set Database Credential ............................................................................................................................ 9 Create Database ....................................................................................................................................... 9 Create Table ............................................................................................................................................ 10 Create Data Records ............................................................................................................................... 11 4. SAMPLE CODE ..................................................................................................................... 12 Creating JDBC Application ....................................................................................................................... 12 Sample Code ........................................................................................................................................... 12 5. DRIVER TYPES ...................................................................................................................... 16 What is JDBC Driver?............................................................................................................................... 16 JDBC Drivers Types .................................................................................................................................. 16 Which Driver should be Used? ................................................................................................................ 19 6. CONNECTIONS .................................................................................................................... 20 Import JDBC Packages ............................................................................................................................. 20 Register JDBC Driver ............................................................................................................................... 20 Database URL Formulation ..................................................................................................................... 22 Create Connection Object ....................................................................................................................... 22 Closing JDBC Connections ....................................................................................................................... 24 7. STATEMENTS ...................................................................................................................... 25 The Statement Objects ........................................................................................................................... 25 The PreparedStatement Objects ............................................................................................................. 29 Prepare - Example Code .......................................................................................................................... 31 The CallableStatement Objects ............................................................................................................... 34 8. RESULT SETS ....................................................................................................................... 40 Type of ResultSet .................................................................................................................................... 40 Concurrency of ResultSet ........................................................................................................................ 41 iii Navigating a Result Set ........................................................................................................................... 41 Navigate - Example Code ........................................................................................................................ 43 Viewing a Result Set ............................................................................................................................... 46 Viewing - Example Code .......................................................................................................................... 47 Updating a Result Set .............................................................................................................................. 51 Updating - Example Code .......................................................................................................................

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    31 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us