Copyright  Oracle Corporation, 1998. All rights reserved. 4 Accessing a Database Using JBCL.

Slides:



Advertisements
Similar presentations
BACS 485—Database Management Advanced SQL Overview Advanced DDL, DML, and DCL Commands.
Advertisements

Copyright  Oracle Corporation, All rights reserved. 4 Aggregating Data Using Group Functions.
Copyright  Oracle Corporation, All rights reserved. 3 JavaBeans: Reusing Application Components.
Copyright  Oracle Corporation, All rights reserved. 2 Java and Databases: An Overview.
Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
Introduction To SQL Lynnwood Brown President System Managers LLC Copyright System Managers LLC 2003 all rights reserved.
12-1 Copyright  Oracle Corporation, All rights reserved. What Is a View? EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
Restricting and sorting data 16 May May May Created By Pantharee Sawasdimongkol.
1Eyad Alshareef Enhanced Guide to Oracle 10g Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data.
Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
Copyright  Oracle Corporation, All rights reserved. 6 Subqueries.
Copyright  Oracle Corporation, All rights reserved. 6 Writing Correlated Subqueries.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
A Guide to SQL, Seventh Edition. Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Copyright  Oracle Corporation, All rights reserved. 9 Manipulating Data: INSERT, UPDATE, DELETE.
Writing Basic SQL statement 2 July July July Create By Pantharee Sawasdimongkol.
Logical Operators Operator AND OR NOT Meaning Returns TRUE if both component conditions are TRUE Returns TRUE if either component condition is TRUE Returns.
o At the end of this lesson, you will be able to:  Describe the life-cycle development phases  Discuss the theoretical and physical aspects of a relational.
Copyright  Oracle Corporation, All rights reserved. I Introduction.
Copyright © 2007, Oracle. All rights reserved. Managing Concurrent Requests.
4-1 Copyright  Oracle Corporation, All rights reserved. Data Manipulation Language (DML)
Copyright  Oracle Corporation, All rights reserved. 1 Writing Basic SQL Statements.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Introduction to Relational Databases &
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Cursors These slides are licensed under.
Subqueries.
Subqueries.
2 Writing Basic SELECT Statements. 1-2 Copyright  Oracle Corporation, All rights reserved. Capabilities of SQL SELECT Statements Selection Projection.
Copyright  Oracle Corporation, All rights reserved. Writing Basic SQL Statements.
Copyright س Oracle Corporation, All rights reserved. I Introduction.
7 Multiple-Column Subqueries. 7-2 Objectives At the end of this lesson, you should be able to: Write a multiple-column subquery Describe and explain the.
10 Creating and Managing Tables Objectives At the end of this lesson, you will be able to: Describe the main database objects Create tables Describe.
10-1 Copyright  Oracle Corporation, All rights reserved. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns.
Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
Copyright  Oracle Corporation, All rights reserved. 6 Accessing a Database Using the JDBC API.
Session 2: SQL (A): Parts 1 and 2 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram.
Copyright  Oracle Corporation, All rights reserved. 7 Accessing a Database Using SQLJ.
Course ILT Forms and queries Unit objectives Create forms by using AutoForm and the Form Wizard, and add or modify form headers and footers Open and enter.
8 Producing Readable Output with SQL*Plus. 8-2 Objectives At the end of this lesson, you should be able to: Produce queries that require an input variable.
Copyright  Oracle Corporation, All rights reserved. 5 More on Creating Database Forms Using AppBuilder.
Copyright  Oracle Corporation, All rights reserved. 11 Including Constraints.
Copyright  Oracle Corporation, All rights reserved. Introduction.
1 Writing Basic SQL Statements. 1-2 Objectives At the end of this lesson, you should be able to: List the capabilities of SQL SELECT statements Execute.
I-1 Copyright س Oracle Corporation, All rights reserved. Data Retrieval.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
9 Manipulating Data. 9-2 Objectives At the end of this lesson, you should be able to: Describe each DML statement Insert rows into a table Update rows.
Copyright  Oracle Corporation, All rights reserved. 12 Creating Views.
Copyright  Oracle Corporation, All rights reserved. 8 Producing Readable Output with SQL*Plus.
An Introduction To SQL Part 2 (Special thanks to Geoff Leese)
1 Information Retrieval and Use (IRU) An Introduction To SQL Part 2.
Copyright س Oracle Corporation, All rights reserved. I Introduction.
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
2-1 Limiting Rows Using a Selection “…retrieve all employees in department 10” EMP EMPNO ENAME JOB... DEPTNO 7839KINGPRESIDENT BLAKEMANAGER CLARKMANAGER.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Grouping These slides are licensed under.
Creating and Managing Tables 14. ObjectivesObjectives After completing this lesson, you should be able to do the following: After completing this lesson,
Copyright س Oracle Corporation, All rights reserved. 12 Creating Views.
1-1 Copyright  Oracle Corporation, All rights reserved. Logging In to SQL*Plus From Windows environment:From Windows environment: From command line:From.
Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
Writing Basic SQL Statements. Objectives After completing this lesson, you should be able to do the following: –List the capabilities of SQL SELECT statements.
Copyright س Oracle Corporation, All rights reserved. 1 Writing Basic SQL Statements.
Communicating with a RDBMS Using SQL Database SQL> SELECT loc 2 FROM dept; SQL> SELECT loc 2 FROM dept; SQL statement is entered Statement is sent to database.
Subqueries.
Subqueries Schedule: Timing Topic 25 minutes Lecture
Manipulating Data Schedule: Timing Topic 40 minutes Lecture
Interacting with the Oracle Server
Writing Correlated Subqueries
What Is a View? EMPNO ENAME JOB EMP Table EMPVU10 View
Subqueries Schedule: Timing Topic 25 minutes Lecture
Subqueries Schedule: Timing Topic 25 minutes Lecture
Presentation transcript:

Copyright  Oracle Corporation, All rights reserved. 4 Accessing a Database Using JBCL

Copyright  Oracle Corporation, All rights reserved. 4-2 Objectives After completing this lesson, you should be able to do the following: Describe the key JBCL data components Specify properties for JBCL data component Build a simple form to query and update a database After completing this lesson, you should be able to do the following: Describe the key JBCL data components Specify properties for JBCL data component Build a simple form to query and update a database

Copyright  Oracle Corporation, All rights reserved. 4-3 Overview JBCL includes many components that simplify database connectivity JOB CLERK SALESMAN MANAGER ENAME ADAMS ALLEN BLAKE CLARK SAL

Copyright  Oracle Corporation, All rights reserved. 4-4 Getting Started: The Database Component Add a Database component to your applet Manages the database connection Add a Database component to your applet Manages the database connection

Copyright  Oracle Corporation, All rights reserved. 4-5 Configuring the Database Properties The Database properties govern the way in which the database connection is made Connection details Transaction isolation level Use schema and table name? Use space padding and statement caching? The Database properties govern the way in which the database connection is made Connection details Transaction isolation level Use schema and table name? Use space padding and statement caching?

Copyright  Oracle Corporation, All rights reserved. 4-6 Specifying connection Details: JDBC Driver connection is a complex property, and is set using the Connection Editor Driver tab specifies the JDBC Driver to use: connection is a complex property, and is set using the Connection Editor Driver tab specifies the JDBC Driver to use:

Copyright  Oracle Corporation, All rights reserved. 4-7 Specifying connection Details: Database Details In the Database tab, specify details for the database Details required here depend on which driver you have selected In the Database tab, specify details for the database Details required here depend on which driver you have selected

Copyright  Oracle Corporation, All rights reserved. 4-8 Testing the Database Connection In the Test Connection tab, test that the database connection can be established Tests database URL and availability of the JDBC driver In the Test Connection tab, test that the database connection can be established Tests database URL and availability of the JDBC driver

Copyright  Oracle Corporation, All rights reserved. 4-9 Code Generated by the Connection Editor Here is an example of the code generated by the Connection Editor public class Applet1 extends Applet { public void jbInit()… { … database1.setConnection( new borland.sql.dataset.ConnectionDescriptor( "scott", "tiger", false, "oracle.jdbc.driver.OracleDriver")); }

Copyright  Oracle Corporation, All rights reserved Performing a Query: The QueryDataSet Component Add a QueryDataSet component to your applet Specifies the SQL query string Add a QueryDataSet component to your applet Specifies the SQL query string

Copyright  Oracle Corporation, All rights reserved Configuring the QueryDataSet Properties The QueryDataSet properties define the SQL query to be executed SQL query string Sort criteria Should errors be displayed? How is modified data written to the database? The QueryDataSet properties define the SQL query to be executed SQL query string Sort criteria Should errors be displayed? How is modified data written to the database?

Copyright  Oracle Corporation, All rights reserved Configuring a QueryDataSet : Specifying the query Property Specify the Database component, and the SQL query string 1 2 3

Copyright  Oracle Corporation, All rights reserved Testing the Query Click the Test Query button to verify that the SQL string against the Database Displays the outcome here

Copyright  Oracle Corporation, All rights reserved Code Generated by the Query Editor Example: public void jbInit()… { … queryDataSet1.setQuery( new borland.sql.dataset.QueryDescriptor( database1, // Database instance "select ENAME, SAL from EMP where SAL < 2500", null, // No parameterRow ref true, // Execute immediately? false)); // Asynchronous exec? }

Copyright  Oracle Corporation, All rights reserved Guided Practice: Specifying Complex SQL Strings Given the following EMP table: EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO and the following DEPT table: DEPTNO, DNAME, LOC define a SQL query that gets the employee name, department name, and salary for all clerks, in order of salary Given the following EMP table: EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO and the following DEPT table: DEPTNO, DNAME, LOC define a SQL query that gets the employee name, department name, and salary for all clerks, in order of salary

Copyright  Oracle Corporation, All rights reserved Using QueryDataSet Results QueryDataSet executes a SQL string, and caches the data set locally Results can be displayed using data- aware controls Data-aware controls appear in Controls tab, with gray grid background QueryDataSet executes a SQL string, and caches the data set locally Results can be displayed using data- aware controls Data-aware controls appear in Controls tab, with gray grid background

Copyright  Oracle Corporation, All rights reserved Example: Displaying a Data Set in a GridControl Add a GridControl to the applet Specify its dataSet property Add a GridControl to the applet Specify its dataSet property

Copyright  Oracle Corporation, All rights reserved What Happens at Run Time? The Database connection is opened The QueryDataSet query is executed, and results are cached locally Results are displayed in bound data controls The Database connection is opened The QueryDataSet query is executed, and results are cached locally Results are displayed in bound data controls

Copyright  Oracle Corporation, All rights reserved Modifying the Display Format Each of the columns in the QueryDataSet has its own properties

Copyright  Oracle Corporation, All rights reserved Display and Edit Masks Each column can have display and edit masks

Copyright  Oracle Corporation, All rights reserved Data Validation A validation routine can be defined for each column void column2_validate(DataSet ds, Column col, Variant var) throws Exception { BigDecimal min = new BigDecimal(200); BigDecimal sal = var.getAsBigDecimal(); if (sal.compareTo(min) < 0) throw new VetoException("Salary too small"); }

Copyright  Oracle Corporation, All rights reserved Viewing the Customized Columns at Run Time The appearance of the GridControl after modifying the column properties:

Copyright  Oracle Corporation, All rights reserved Using Other Data-Aware Controls Other data-aware controls can be added Specify the dataSet and columnName properties for each control Other data-aware controls can be added Specify the dataSet and columnName properties for each control

Copyright  Oracle Corporation, All rights reserved Data-Aware Controls at Run Time The data-aware controls display data for the “current row” Synchronized with the GridControl Edits are reflected in all controls The data-aware controls display data for the “current row” Synchronized with the GridControl Edits are reflected in all controls

Copyright  Oracle Corporation, All rights reserved Navigating a Data Set Using a NavigatorControl Helps you to scroll, save, delete, and modify the data set NavigatorControl

Copyright  Oracle Corporation, All rights reserved Scrolling with NavigatorControl NavigatorControl includes buttons to scroll through the data set First, Prior, Next, Last NavigatorControl includes buttons to scroll through the data set First, Prior, Next, Last

Copyright  Oracle Corporation, All rights reserved Modifying Rows with NavigatorControl NavigatorControl includes buttons to modify rows Insert, Delete, Post, Cancel, Ditto NavigatorControl includes buttons to modify rows Insert, Delete, Post, Cancel, Ditto

Copyright  Oracle Corporation, All rights reserved Saving and Refreshing Data with NavigatorControl NavigatorControl includes buttons to save data, and to refresh the QueryDataSet with the latest data Save, Refresh NavigatorControl includes buttons to save data, and to refresh the QueryDataSet with the latest data Save, Refresh

Copyright  Oracle Corporation, All rights reserved Navigating Rows Programmatically void btnFirst_actionPerformed(ActionEvent e) { try { queryDataSet1.first(); } catch (DataSetException dse) { } }

Copyright  Oracle Corporation, All rights reserved Guided Practice: Navigating Programmatically NavigatorControl provides the following additional buttons: How can the same effect be achieved programmatically? NavigatorControl provides the following additional buttons: How can the same effect be achieved programmatically?

Copyright  Oracle Corporation, All rights reserved Locating Rows in a Data Set Using a LocatorControl LocatorControl

Copyright  Oracle Corporation, All rights reserved LocatorControl at Run Time LocatorControl provides an incremental search on string columns

Copyright  Oracle Corporation, All rights reserved Customizing Database “Save” Behavior A QueryResolver can be used to fine- tune the way data is saved to a database QueryResolver

Copyright  Oracle Corporation, All rights reserved void queryResolver1_deletingRow( ReadWriteRow readWriteRow, ResolverResponse resolverResponse)…{ BigDecimal hi = new BigDecimal(6000); BigDecimal sal = readWriteRow.getBigDecimal("SAL"); if (sal.compareTo(hi) >= 0) resolverResponse.skip(); } Useful QueryResolver Events QueryResolver triggers events for you to customize behavior deletingRow

Copyright  Oracle Corporation, All rights reserved Associating a QueryDataSet with a QueryResolver The QueryDataSet can now use the QueryResolver to resolve its save operations

Copyright  Oracle Corporation, All rights reserved Summary The JBCL provides many components to simplify database connectivity Database component QueryDataSet component Data-aware controls, such as GridControl NavigatorControl and LocatorControl components The JBCL provides many components to simplify database connectivity Database component QueryDataSet component Data-aware controls, such as GridControl NavigatorControl and LocatorControl components

Copyright  Oracle Corporation, All rights reserved Practice 4-1 Overview Use the JBCL data components to connect to a database, and perform a query Display the result set using data-aware controls Customize the controls using edit and display masks Navigate the result set using the Navigator and Locator controls Use the JBCL data components to connect to a database, and perform a query Display the result set using data-aware controls Customize the controls using edit and display masks Navigate the result set using the Navigator and Locator controls

Copyright  Oracle Corporation, All rights reserved Full Notes Page for Practices

Copyright  Oracle Corporation, All rights reserved Full Notes Page for Practices

Copyright  Oracle Corporation, All rights reserved Full Notes Page for Practices

Copyright  Oracle Corporation, All rights reserved Full Notes Page for Practices

Copyright  Oracle Corporation, All rights reserved. 4-42