Download presentation
Presentation is loading. Please wait.
Published byLorena Brown Modified over 9 years ago
1
A CCESSING D ATABASES WITH JDBC CH 24 C S 442: A DVANCED J AVA P ROGRAMMING
2
A database is an organized collection of data. A database management system ( DBMS ) provides mechanisms for storing, organizing, retrieving and modifying data for many users. Database management systems allow for the access and storage of data without concern for the internal representation of data. A language called SQL is the international standard language used almost universally with relational databases to perform queries and to manipulate data. Java programs communicate with databases and manipulate their data using the Java Database Connectivity (JDBC™) API. A JDBC driver enables Java applications to connect to a database in a particular DBMS and allows you to manipulate that database using the JDBC API.
3
Today’s most popular database systems are relational databases. A relational database is a logical representation of data that allows the data to be accessed A relational database stores data in tables. Tables are composed of rows, and rows are composed of columns in which values are stored. primary key a column (or group of columns) with a unique value that cannot be duplicated in other rows. Good examples of primary key columns are a social security number and employee ID number.
4
Different users of a database are often interested in different data and different relationships among the data. Most users require only subsets of the rows and columns For example, you might select data from the Employee table to create a result that shows where each department is located, presenting the data sorted in increasing order by department number. Some popular relational database management systems ( RDBMSs ) are Microsoft SQL Server, Oracle and MySQL.
5
entity-relationship ( ER ) diagram is diagram shows the database tables and the relationships among them. The first compartment in each box contains the table’s name and the remaining compartments contain the table’s columns. * There’s a one-to-many relationship between a primary key and a corresponding foreign key.
6
T ABLES WILL BE USED IN SQL QUERY :-
8
S TRUCTURED Q UERY L ANGUAGE (SQL)
9
B ASIC SELECT Q UERY : The basic form of a SELECT query the asterisk (*) wildcard character indicates that all columns from the tableName table should be retrieved. For example, to retrieve all the data in the Authors table, use Example :
10
WHERE C LAUSE The basic form of a query with selection criteria For example, to select the Title, EditionNumber and Copyright columns from table Titles for which the Copyright date is greater than 2010, use the query:
11
P ATTERN M ATCHING : Z ERO OR M ORE C HARACTERS Operator LIKE is used for pattern matching with wildcard characters percent ( % ) and underscore (_). A pattern that contains a percent character (%) searches for strings that have zero or more characters at the percent character’s position in the pattern. Example:
12
P ATTERN M ATCHING : A NY C HARACTER An underscore ( _ ) in the pattern string indicates a single wildcard character at that position in the pattern.
13
ORDER BY C LAUSE The basic form of a query with an ORDER BY clause ASCENDING ORDER :
14
D ESCENDING O RDER :
15
S ORTING B Y M ULTIPLE C OLUMNS
16
C OMBINING THE WHERE AND ORDER BY C LAUSES
17
M ERGING D ATA FROM M ULTIPLE T ABLES : INNER JOIN
18
INSERT S TATEMENT
19
UPDATE S TATEMENT the WHERE clause can be simplified as follows:
20
DELETE S TATEMENT
21
M ANIPULATING D ATABASES WITH JDBC 1 Connecting to and Querying a Database The example performs a simple query on the books database that retrieves the entire Authors table and displays the data. The program illustrates connecting to the database, querying the database and processing the result.
23
Output:
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.