Preview JDBC Tutorial

Total Page:16

File Type:pdf, Size:1020Kb

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 .......................................................................................................................
Recommended publications
  • Staroffice 6.0 Software Setting up Database Connections
    StarOffice™ 6.0 Software Setting Up Database Connections Sun Microsystems, Inc. 901 San Antonio Road Palo Alto, CA 94303 U.S.A. 650-960-1300 Part No. 817-0364-05 September 2002, Revision A Copyrights and Trademarks Copyright © 2002 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. All rights reserved. Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is described in this document. In particular, and without limitation, these intellectual property rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or more additional patents or pending patent applications in the U.S. and in other countries. This document and the product to which it pertains are distributed under licenses restricting their use, copying, distribution, and decompilation. No part of the product or of this document may be repro- duced in any form by any means without prior written authorization of Sun and its licensors, if any. Third-party software, including font technology, is copyrighted and licensed from Sun suppliers. This product is based in part on the work of the Independent JPEG Group, The FreeType Project and the Catharon Typography Project. Portions Copyright 2000 SuSE, Inc. Word for Word Copyright © 1996 Inso Corp. International CorrectSpell spelling correction system Copyright © 1995 by Lernout & Hauspie Speech Products N.V. All rights reserved. Source code for portions of this product are available under the Mozilla Public License at the following sites: http://www.mozilla.org/, http://www.jclark.com/, and http://www.gingerall.com.
    [Show full text]
  • Filemaker 16 ODBC and JDBC Guide
    FileMaker®16 ODBC and JDBC Guide © 2004–2017 FileMaker, Inc. All Rights Reserved. FileMaker, Inc. 5201 Patrick Henry Drive Santa Clara, California 95054 FileMaker, FileMaker Go, and the file folder logo are trademarks of FileMaker, Inc. registered in the U.S. and other countries. FileMaker WebDirect and FileMaker Cloud are trademarks of FileMaker, Inc. All other trademarks are the property of their respective owners. FileMaker documentation is copyrighted. You are not authorized to make additional copies or distribute this documentation without written permission from FileMaker. You may use this documentation solely with a valid licensed copy of FileMaker software. All persons, companies, email addresses, and URLs listed in the examples are purely fictitious and any resemblance to existing persons, companies, email addresses, or URLs is purely coincidental. Credits are listed in the Acknowledgments documents provided with this software. Mention of third-party products and URLs is for informational purposes only and constitutes neither an endorsement nor a recommendation. FileMaker, Inc. assumes no responsibility with regard to the performance of these products. For more information, visit our website at http://www.filemaker.com. Edition: 01 Contents Chapter 1 Introduction 5 About this guide 5 Where to find FileMaker documentation 5 About ODBC and JDBC 6 Using FileMaker software as an ODBC client application 6 Importing ODBC data 6 Adding ODBC tables to the relationships graph 6 Using a FileMaker database as a data source 7 Accessing a
    [Show full text]
  • Mysql Query Browser Mysql Query Browser This Is a Translation of the Mysql Query Browser Manual That Can Be Found at Dev.Mysql.Com
    MySQL Query Browser MySQL Query Browser This is a translation of the MySQL Query Browser Manual that can be found at dev.mysql.com. The original MySQL Query Browser Manual is in English, and this translation is not necessarily as up to date as the English version. Esta es una traduccion del manual de MySQL Query Browser el cual puede ser encontrado en dev.mysql.com. El Manual original de MySQL Query Browser se encuentra en Inglés, y esta traduccion no necesariamente es tan actualizada como la versión en Inglés. Edwin Cruz <ecruz @ medel.com.mx> ha traducido este manual del Inglés. El es gerente de sistemas y vive en Aguascalientes, México. Edwin cumplió su educación en 2005 con grado de ingenieria en ciencias de la computa- ción. Como desarrollador, Edwin ha estado trabajando con LAMP Stack por tres años. Antes de obtener su empleo actual, en una compañia de transporte, Edwin trabajo en Texas Instruments Mexico. Resumen Este es el Manual de MySQL Query Browser Documento generado en: 2010-03-14 (revision: 542) Copyright © 1997-2007 MySQL AB, 2008-2010 Sun Microsystems, Inc. All rights reserved. U.S. Government Rights - Commercial software. Govern- ment users are subject to the Sun Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its supplements. Use is sub- ject to license terms. Sun, Sun Microsystems, the Sun logo, Java, Solaris, StarOffice, MySQL Enterprise Monitor 2.0, MySQL logo™ and MySQL™ are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. UNIX is a registered trademark in the U.S.
    [Show full text]
  • Chapter 8 Getting Started with Base
    Getting Started Guide Chapter 8 Getting Started with Base OpenOffice.org’s Database Component Copyright This document is Copyright © 2008 by its contributors as listed in the section titled Authors. You may distribute it and/or modify it under the terms of either the GNU General Public License, version 3 or later, or the Creative Commons Attribution License, version 3.0 or later. All trademarks within this guide belong to their legitimate owners. Authors Dan Lewis Iain Roberts Magnus Adielsson Jean Hollis Weber Feedback Maintainer: Dan Lewis Please direct any comments or suggestions about this document to: [email protected] Acknowledgments As the maintainer of this document, I would like to personally thank the other authors of it. Without them, this document would not have the quality it does. Neither would it contain as much information. Iain Roberts and Magnus Adielsson offered many sound suggestions on content as well as format. Jean Hollis Weber with many years of technical writing experience has suggested many changes which have made this document much more understandable. Special thanks also go to those who have translated this document into other languages so that non-English speaking people have access to this information. Publication date and software version Published 13 October 2008. Based on OpenOffice.org 3.0. You can download an editable version of this document from http://oooauthors.org/en/authors/userguide3/published/ Contents Copyright...............................................................................................2
    [Show full text]
  • Chapter 3 DB Gateways.Pptx
    Prof. Dr.-Ing. Stefan Deßloch AG Heterogene Informationssysteme Geb. 36, Raum 329 Tel. 0631/205 3275 [email protected] Chapter 3 DB-Gateways Outline n Coupling DBMS and programming languages n approaches n requirements n Programming Model (JDBC) n overview n DB connection model n transactions n Data Access in Distributed Information System Middleware n DB-Gateways n architectures n ODBC n JDBC n SQL/OLB – embedded SQL in Java n Summary 2 © Prof.Dr.-Ing. Stefan Deßloch Middleware for Information Systems Coupling Approaches – Overview n Static Embedded SQL n static SQL queries are embedded in the programming language n cursors to bridge so-called impedance mismatch n preprocessor converts SQL into function calls of the programming language n potential performance advantages (early query compilation) n vendor-specific precompiler and target interface n resulting code is not portable n Dynamic Embedded SQL n SQL queries can be created dynamically by the program n character strings interpreted as SQL statements by an SQL system n preprocessor is still required n only late query compilation n same drawbacks regarding portability as for static embedded n Call-Level Interface (CLI) n standard library of functions that can be linked to the program n same capabilities as (static and dynamic) embedded n SQL queries are string parameters of function invocation n avoids vendor-specific precompiler, allows to write/produce binary-portable programs 3 © Prof.Dr.-Ing. Stefan Deßloch Middleware for Information Systems Coupling Approaches (Examples)
    [Show full text]
  • Oracle/Sun Microsystems: the Challenge of Reviewing a Merger Involving Open Source Software
    Mergers Oracle/Sun Microsystems: The challenge of reviewing a merger involving open source software Carl-Christian Buhr, Sabine Crome, Adrian Lübbert, Vera Pozzato, Yvonne Simon, Robert Thomas (1) 1. Introduction (1) 2. Oracle, Sun and the IT stack On 21 January 2010 the Commission uncondition- The US company Oracle is a major business soft- ally cleared the planned takeover of Sun Microsys- ware vendor. It develops and distributes enterprise tems (‘Sun’), a software and hardware vendor, by software solutions and related services, including Oracle Corporation (‘Oracle’), one of the world’s middleware, databases and enterprise application leading software companies. The clearance followed software. Sun is active in hardware (servers, desk- an extensive investigation into the database market tops, microelectronics, and storage devices) and where Oracle was the leading proprietary vendor software, including operating systems, Java software and Sun the leading open source vendor. The case development technology, middleware, database soft- also attracted a certain level of public attention and ware and related services. triggered reactions by many parties. The legal test The product offerings of Oracle and Sun can be applied in this case was not based on the acquisi- seen as part of an IT or technology ‘stack’ which tion or strengthening of a dominant position but consists of the various hardware and software on the elimination of an important competitive components necessary for companies to ultimate- force, which would be Sun’s MySQL. The Horizon- ly use business software applications. Hardware tal Merger Guidelines (2) recognize that some firms, products, including servers, storage units and despite having a relatively small market share may client PCs, constitute the first layer.
    [Show full text]
  • Oracle® Virtual Desktop Infrastructure Update Guide for Version 3.2.2
    Oracle® Virtual Desktop Infrastructure Update Guide for Version 3.2.2 April 2011 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited. The information contained herein is subject to change without notice and is not warranted to be error-free. If you find any errors, please report them to us in writing. If this software or related documentation is delivered to the U.S. Government or anyone licensing it on behalf of the U.S. Government, the following notice is applicable: U.S. GOVERNMENT RIGHTS Programs, software, databases, and related documentation and technical data delivered to U.S. Government customers are "commercial computer software" or "commercial technical data" pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such, the use, duplication, disclosure, modification, and adaptation shall be subject to the restrictions and license terms set forth in the applicable Government contract, and, to the extent applicable by the terms of the Government contract, the additional rights set forth in FAR 52.227-19, Commercial Computer Software License (December 2007). Oracle USA, Inc., 500 Oracle Parkway, Redwood City, CA 94065.
    [Show full text]
  • Netbeans Crud Desktop Application
    Netbeans Crud Desktop Application Is Erny eosinophilic or gabbroitic when disparages some telephoner observes microscopically? Stotious Ephrem caw: he fortify his grumpiness strongly and worshipfully. Is Sampson always cable-laid and impassionate when upraising some guarders very lustily and priggishly? Create GUl ApplicationDesktop Application with Login System CRUD. I often find another need got a quick CRUD application to database Read Update. This document is based on these Ant-based NetBeans CRUD Application Tutorial. CRUD generation and multiple tables in Netbeans IDE Users. The NetBeans Platform provides all of these out of drain box. The user interface for contributing an observable collection on hold because of your free account is a comment form width and try again and choose connect and news. In this tutorial we show about how they develop a web application CRUD. This tutorial covers implementing CRUD database operations using Java Persistence APIJPA for desktop applications. The application to confirm your ui application in five columns of their respective codes to create much. It prompts that when out our support or any sources page of a desktop database. Select the Java category from Projects select Java Application. I create help creating a simple Java database type application. Creating NetBeans Platform CRUD Application Using Maven. To build a basic Angular 11 CRUD application with Reactive Forms that includes. Flutter sqlite crud Persistent storage can be local for caching network calls. Recommend Grails myself included if I need two simple CRUD web framework but cost me. Want to test that provides useful methods in netbeans ide generates a larger application.
    [Show full text]
  • Oracle Open Office Frequently Asked Questions
    Oracle Open Office: Frequently Asked Questions Overview processing, spreadsheets, presentations, drawing, database, mail and calendar, and Web publishing. Its user interface is You need to cut costs without sacrificing productivity. Because intuitive and easy to use. Plus, it’s multiplatform and available you may have a significant investment in Microsoft Office on the Microsoft Windows, Macintosh OS X, and Linux documents and files, you may feel as if you have no choice but platforms, as well as on Oracle Solaris operating system (OS). to upgrade to the next version of Microsoft Office or renew What are they key features in Oracle Open Office 3? your three-year maintenance contract when it comes due. Briefly, key features include But there is an alternative to Microsoft Office that is being used by millions of businesses and individuals around the • Many productivity features that make common tasks much world. Oracle Open Office 3 software is a complete, feature- easier to perform rich office productivity product that costs approximately 75 • Support for Microsoft Windows (32 bit and 64 bit), Oracle percent less than Microsoft Office. It includes powerful Solaris, Macintosh OS X, and Linux programs for word processing, spreadsheets, presentations, drawing, database, graphics, and Web publishing. Its user • PDF import, editing, and export interface is intuitive and easy to use. It offers improved • Microsoft Office compatibility, blog and wiki publishing Import of Microsoft Office files, including 2007 XML files features, and the ability to edit PDF documents—all in a • Web participation tools such as a blogger and wiki publisher multiplatform office suite that is available on Microsoft Windows, Oracle Solaris, Macintosh OS X, and Linux • Antialiasing platforms.
    [Show full text]
  • Creating a Java Platform Enterprise Appliance Using the Glassfish
    Creating a Java™ Platform, Enterprise Edition (Java EE Platform) Appliance Using GlassFish™ and OpenSolaris™ Peter Karlsson, Technology Evangelist Lee Chuk Munn, Staff Engineer Learn how we build a JavaEE application appliance Under funded Under pressure for One Appliance per GeekTM (OAPG) cause! 2008 JavaOneSM Conference | java.sun.com/javaone | 2 Agenda OpenSolaris™ Project / GlassFish Appliance OpenSolaris Project • Short Introduction to Solaris ZFS • (Another) Short Introduction to SMF GlassFish Application Server Appliance Features Overview • Installing Applications • Integration with SMF Summary 2008 JavaOneSM Conference | java.sun.com/javaone | 3 OpenSolaris/GlassFish Appliance 2008 JavaOneSM Conference | java.sun.com/javaone | 4 What is an Appliance? An instrument or device designed for a particular use or function • A solution to solving problem by enabling the proper function Typically hardware and software bundled and tightly integrated Example of appliance • Toaster • Wireless router 2008 JavaOneSM Conference | java.sun.com/javaone | 5 Criteria for an Appliance* Purpose • Scope – scope of operation • Design – native or packaged • Ends not means – what it achieves rather than how it is done Convenience • Ease of use – aim for plug-and-play • Simplicity – if you need to open it up, then it is not simple • Compatibility – harmony with the environment Value • Alignment – align to the business requirements • Cost – lower TCO and should cost less than sum of parts • Performance – does not only refer to speed but for achieving its
    [Show full text]
  • Remote Mysql Database)
    Sun Virtual Desktop Infrastructure Update Guide for Version 3.1 April 2011 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited. The information contained herein is subject to change without notice and is not warranted to be error-free. If you find any errors, please report them to us in writing. If this software or related documentation is delivered to the U.S. Government or anyone licensing it on behalf of the U.S. Government, the following notice is applicable: U.S. GOVERNMENT RIGHTS Programs, software, databases, and related documentation and technical data delivered to U.S. Government customers are "commercial computer software" or "commercial technical data" pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such, the use, duplication, disclosure, modification, and adaptation shall be subject to the restrictions and license terms set forth in the applicable Government contract, and, to the extent applicable by the terms of the Government contract, the additional rights set forth in FAR 52.227-19, Commercial Computer Software License (December 2007). Oracle USA, Inc., 500 Oracle Parkway, Redwood City, CA 94065.
    [Show full text]
  • Openoffice.Org Base Macro Programming by Andrew Pitonyak
    OpenOffice.org Base Macro Programming By Andrew Pitonyak Last Modified Tuesday, July 28, 2009 at 09:54:04 PM Document Revision: 43 Information Page Copyright This document is Copyright © 2005-2009 by its contributors as listed in the section titled Authors. You can distribute it and/or modify it under the terms of the Creative Commons Attribution License, version 2.0 or later (http://creativecommons.org/licenses/by/2.0/). All trademarks within this guide belong to their legitimate owners. Authors Andrew Pitonyak Feedback Maintainer: Andrew Pitonyak [[email protected]] Please direct any comments or suggestions about this document to: [email protected] Acknowledgments I find it difficult to properly credit all of my sources, because so many people are helpful in an en devour of this size. There are, however, a few people who do indeed stand out in my mind as having provided significant encouragement. I have no explanation as to precisely why my wife Michelle allows me to spend so much time working with OpenOffice.org. Perhaps she is really the person that you should thank for my productivity. I Love you Michelle, you complete me. All of the people with whom I have interacted at Sun Microsystems have been very tolerant and patient with my endless questions. In the creation of this document, Frank Schönheit, however stands out in this regard. Mr. Schönheit spends a lot of time helping people with problems and questions, and most notable for me, he answers my questions. Thank you Frank! There is a large community volunteering their time with OpenOffice.org.
    [Show full text]