This document discusses how Java programs can connect to and query databases using JDBC (Java Database Connectivity). It explains that JDBC provides a standard interface for connecting to different database types and allows programs to send SQL statements to a database. The document also provides an example Java program that uses JDBC to connect to a database, execute a query to retrieve all records from the authors table, and display the results.
Database Programming: The Design of JDBC, The Structured Query Language, Basic JDBC Programming Concepts,
Result Sets, Metadata, Row Sets, Transactions
JDBC provides a standard interface for connecting to relational databases from Java applications. It establishes a connection with a database, allows sending SQL statements to it, and processing the results. The key classes and interfaces in JDBC are located in the java.sql package. JDBC supports connecting to all major databases and provides a consistent API for database access.
JDBC stands for Java Database Connectivity and is an API that allows Java programs to execute SQL statements and retrieve results from a database. It uses JDBC drivers to connect to different database types and provides interfaces for establishing a connection, executing queries, and processing result sets. Some common uses of JDBC include building Java applications, applets, servlets, and JSPs that need to access and manipulate data stored in relational databases.
JDBC provides an API for accessing databases from Java that simplifies development, supports metadata access, and allows connection pooling. It includes interfaces for application writers and driver writers, with popular drivers available for databases like Oracle, MySQL, and SQL Server. JDBC drivers can be Type 1 (JDBC-ODBC bridge), Type 2 (partial JDBC), Type 3 (pure Java for middleware), or Type 4 (direct connection).
Core Java Programming Language (JSE) : Chapter XIII - JDBCWebStackAcademy
JDBC is a Java API that allows Java programs to connect to databases. It provides methods to query and update data and works with various database drivers. The key classes in JDBC include Connection, Statement, PreparedStatement, and ResultSet. Connection objects are used to establish a connection to the database. Statement objects are used to execute SQL statements. PreparedStatement objects are used to execute parameterized SQL statements. ResultSet objects contain the results of queries.
This document provides an introduction and overview of Java Database Connectivity (JDBC). It discusses what JDBC is, the different types of JDBC drivers, how to connect to databases using JDBC, and how to execute SQL statements and process result sets. It also covers how to access database metadata and provides examples of using JDBC to connect to and query a Microsoft Access database.
This document provides an overview of Java Database Connectivity (JDBC) including:
- JDBC provides a vendor-neutral way to connect Java applications to databases.
- It describes the basic components and architecture of JDBC including drivers, connections, statements, and result sets.
- It explains how to establish a connection to a database using JDBC including installing drivers, getting connections, executing queries, and processing result sets.
This document provides an overview of Spring's transaction management capabilities. It discusses how Spring provides a uniform transaction management API that can work with various transaction technologies like JDBC, Hibernate, JPA etc. It also describes how transactions can be handled programmatically using the TransactionTemplate or directly through the transaction manager. Finally, it covers Spring's declarative transaction support using XML or annotations.
Database Programming: The Design of JDBC, The Structured Query Language, Basic JDBC Programming Concepts,
Result Sets, Metadata, Row Sets, Transactions
JDBC provides a standard interface for connecting to relational databases from Java applications. It establishes a connection with a database, allows sending SQL statements to it, and processing the results. The key classes and interfaces in JDBC are located in the java.sql package. JDBC supports connecting to all major databases and provides a consistent API for database access.
JDBC stands for Java Database Connectivity and is an API that allows Java programs to execute SQL statements and retrieve results from a database. It uses JDBC drivers to connect to different database types and provides interfaces for establishing a connection, executing queries, and processing result sets. Some common uses of JDBC include building Java applications, applets, servlets, and JSPs that need to access and manipulate data stored in relational databases.
JDBC provides an API for accessing databases from Java that simplifies development, supports metadata access, and allows connection pooling. It includes interfaces for application writers and driver writers, with popular drivers available for databases like Oracle, MySQL, and SQL Server. JDBC drivers can be Type 1 (JDBC-ODBC bridge), Type 2 (partial JDBC), Type 3 (pure Java for middleware), or Type 4 (direct connection).
Core Java Programming Language (JSE) : Chapter XIII - JDBCWebStackAcademy
JDBC is a Java API that allows Java programs to connect to databases. It provides methods to query and update data and works with various database drivers. The key classes in JDBC include Connection, Statement, PreparedStatement, and ResultSet. Connection objects are used to establish a connection to the database. Statement objects are used to execute SQL statements. PreparedStatement objects are used to execute parameterized SQL statements. ResultSet objects contain the results of queries.
This document provides an introduction and overview of Java Database Connectivity (JDBC). It discusses what JDBC is, the different types of JDBC drivers, how to connect to databases using JDBC, and how to execute SQL statements and process result sets. It also covers how to access database metadata and provides examples of using JDBC to connect to and query a Microsoft Access database.
This document provides an overview of Java Database Connectivity (JDBC) including:
- JDBC provides a vendor-neutral way to connect Java applications to databases.
- It describes the basic components and architecture of JDBC including drivers, connections, statements, and result sets.
- It explains how to establish a connection to a database using JDBC including installing drivers, getting connections, executing queries, and processing result sets.
This document provides an overview of Spring's transaction management capabilities. It discusses how Spring provides a uniform transaction management API that can work with various transaction technologies like JDBC, Hibernate, JPA etc. It also describes how transactions can be handled programmatically using the TransactionTemplate or directly through the transaction manager. Finally, it covers Spring's declarative transaction support using XML or annotations.
This document discusses data access with JDBC using the Spring Framework. It covers Spring's DAO support, exception handling, and approaches for database access including JdbcTemplate, NamedParameterJdbcTemplate, and controlling connections through a DataSource. The core classes provided by Spring simplify JDBC usage and handle common database tasks like opening/closing connections and transactions.
This document provides information on creating a 3-tier web application architecture in Eclipse using JSP. It discusses dividing classes into sub-tasks like views, services and database layers. It also covers creating packages, JSP pages, beans, getters/setters, and service layers. The service layer interacts with the database layer using JDBC to perform operations like registration. The presentation layer posts data to JSP pages, which then call the service layer.
Data access patterns and technologies are discussed. The Data Access Object (DAO) pattern separates data access from business logic. Spring JDBC and myBatis provide APIs for SQL queries and object mapping. Object-relational mapping (ORM) tools like Hibernate reduce code by mapping objects to relational databases but can reduce performance. JDBC template provides basic data access while frameworks offer additional features.
JDBC provides a standard interface for connecting to relational databases from Java applications. It establishes a connection by loading a JDBC driver, then executing SQL statements using objects like Statement and PreparedStatement. Results are retrieved into a ResultSet which can be processed row-by-row. Finally, connections are closed to release resources.
This document provides an overview of using Java Database Connectivity (JDBC) to connect to and interact with relational databases from Java servlets. It describes relational databases and how they organize data into tables. It explains the basic JDBC connection flow of getting a connection, executing SQL statements, and reading results. It also covers key JDBC interfaces like Connection, Statement, and ResultSet. The document provides an example servlet for looking up phone numbers from a database and discusses best practices like reusing connections and using connection pooling.
The document describes Java Database Connectivity (JDBC), which provides Java applications with access to most database systems via SQL. It outlines the JDBC architecture and classes in the java.sql package. JDBC drivers allow applications to connect to databases without using proprietary APIs. There are four types of JDBC drivers. The document also provides an example of how to load a driver, connect to a database, execute a query, and retrieve and display results.
The document discusses a study comparing the SQL optimizer in Oracle and Hive query execution. It aims to understand how the SQL optimizer works in Oracle by generating query plans using Explain and comparing performance to queries executed on Hive. Various query types including single relations, joins, aggregates, and subqueries are executed on both Oracle and Hive and their plans and performance are analyzed and compared to understand how each system optimizes queries and executes them efficiently.
The document discusses JDBC (Java Database Connectivity), which provides a standard interface for connecting to relational databases from Java applications. It describes fundamental JDBC concepts like establishing a connection, executing queries using Statement and PreparedStatement objects, processing result sets, and transaction management. The document also contrasts databases with file systems and provides JDBC driver names and URL formats for popular databases.
JDBC (Java Database Connectivity) provides APIs for Java programs to connect to databases. There are four types of JDBC drivers: Type 1 uses JDBC-ODBC bridge, Type 2 uses a native API, Type 3 is pure Java using a network protocol, and Type 4 is also pure Java using a native database protocol.
To connect to a database using JDBC, a program loads the appropriate JDBC driver, gets a connection, creates statements to execute SQL queries and updates, processes the result set, and closes resources. Prepared statements can be used for repetitive queries to improve performance over regular statements. Overall, JDBC allows Java applications to connect to databases in a standardized way
The document provides an overview of the Java Database Connectivity (JDBC) API. It discusses that JDBC allows Java applications to connect to relational databases and execute SQL statements. It describes the different types of JDBC drivers and the core JDBC classes like Connection, Statement, ResultSet, and their usage. The steps to connect to a database and execute queries using JDBC are outlined. Key concepts like processing result sets, handling errors, batch processing, stored procedures are also summarized.
This document provides information on Spring's enterprise data access features, including Data Access Objects (DAOs), data access templates, exception handling, and integration with ORM frameworks like Hibernate. It discusses how Spring provides DAO support classes, exception translation, and resource management to simplify data access. It also covers Spring's JDBC and Hibernate templates which provide a consistent interface and exception handling for data access code. The document shows how to configure datasources, JDBC templates, and Hibernate session factories in Spring.
JDBC is used to connect Java applications to databases. It uses drivers specific to each database type. The key steps are: 1) loading the driver, 2) defining the connection URL, 3) establishing a connection, 4) creating statements to execute queries or updates, 5) processing result sets, and 6) closing connections. Prepared statements are useful for queries executed multiple times to avoid recompilation. Transactions allow grouping statements that must all succeed or fail together to maintain database consistency.
JDBC (Java Database Connectivity) provides Java applications with access to most database systems via SQL. It defines a standard API for accessing databases in Java. The key classes and interfaces in JDBC include DriverManager, Connection, Statement, PreparedStatement, ResultSet, and DatabaseMetaData. JDBC applications use the DriverManager to obtain a Connection to a database, then execute SQL statements using Statement or PreparedStatement objects to return ResultSet objects containing query results.
This document provides an overview of Java Database Connectivity (JDBC) in 3 sentences or less:
JDBC allows Java programs to connect to and interact with various database systems and provides a standard API for querying and manipulating data in relational databases. The key components of JDBC include the DriverManager, Connection, Statement, and ResultSet objects, and connecting to a database typically involves 4 steps - loading a driver, opening a connection, executing SQL statements via a Statement object, and processing result sets. JDBC offers database independence and ease of administration along with the ability to access any database from Java applications.
The document discusses obtaining a connection to a database in Java using JDBC. It provides code examples of creating a database connection using the DriverManager class and Oracle's JDBC Thin driver. The code inserts a record into an EMP table for demonstration purposes. Best practices for database connectivity in a Java project are then covered, such as using the DAO pattern to separate data access logic from business logic. This improves testability, reusability and flexibility in switching database types.
EJB 3.0 Java Persistence with Oracle TopLinkBill Lyons
This document discusses using Oracle TopLink as a persistence framework with Java Persistence API (JPA) and EJB 3.0. It provides an overview of setting up a TopLink project in JDeveloper, generating entity objects and a session bean, and performing basic CRUD operations. The document demonstrates how to query, insert, update, and delete data using the TopLink APIs.
This document provides an overview of database connectivity in Java. It discusses how Java applications can connect to databases using the JDBC API. It describes the different types of JDBC drivers (types I-IV) and how they work. The key steps in a JDBC program are outlined, including loading a driver, establishing a connection, creating statements, executing queries, and processing result sets. Common SQL statements like SELECT, INSERT, UPDATE and DELETE are explained. Overall, the document serves as an introduction to using the JDBC API to connect Java applications to various database management systems.
Supermarket Management System Project Report.pdfKamal Acharya
Supermarket management is a stand-alone J2EE using Eclipse Juno program.
This project contains all the necessary required information about maintaining
the supermarket billing system.
The core idea of this project to minimize the paper work and centralize the
data. Here all the communication is taken in secure manner. That is, in this
application the information will be stored in client itself. For further security the
data base is stored in the back-end oracle and so no intruders can access it.
More Related Content
Similar to Java Database Connectivity with JDBC.pptx
This document discusses data access with JDBC using the Spring Framework. It covers Spring's DAO support, exception handling, and approaches for database access including JdbcTemplate, NamedParameterJdbcTemplate, and controlling connections through a DataSource. The core classes provided by Spring simplify JDBC usage and handle common database tasks like opening/closing connections and transactions.
This document provides information on creating a 3-tier web application architecture in Eclipse using JSP. It discusses dividing classes into sub-tasks like views, services and database layers. It also covers creating packages, JSP pages, beans, getters/setters, and service layers. The service layer interacts with the database layer using JDBC to perform operations like registration. The presentation layer posts data to JSP pages, which then call the service layer.
Data access patterns and technologies are discussed. The Data Access Object (DAO) pattern separates data access from business logic. Spring JDBC and myBatis provide APIs for SQL queries and object mapping. Object-relational mapping (ORM) tools like Hibernate reduce code by mapping objects to relational databases but can reduce performance. JDBC template provides basic data access while frameworks offer additional features.
JDBC provides a standard interface for connecting to relational databases from Java applications. It establishes a connection by loading a JDBC driver, then executing SQL statements using objects like Statement and PreparedStatement. Results are retrieved into a ResultSet which can be processed row-by-row. Finally, connections are closed to release resources.
This document provides an overview of using Java Database Connectivity (JDBC) to connect to and interact with relational databases from Java servlets. It describes relational databases and how they organize data into tables. It explains the basic JDBC connection flow of getting a connection, executing SQL statements, and reading results. It also covers key JDBC interfaces like Connection, Statement, and ResultSet. The document provides an example servlet for looking up phone numbers from a database and discusses best practices like reusing connections and using connection pooling.
The document describes Java Database Connectivity (JDBC), which provides Java applications with access to most database systems via SQL. It outlines the JDBC architecture and classes in the java.sql package. JDBC drivers allow applications to connect to databases without using proprietary APIs. There are four types of JDBC drivers. The document also provides an example of how to load a driver, connect to a database, execute a query, and retrieve and display results.
The document discusses a study comparing the SQL optimizer in Oracle and Hive query execution. It aims to understand how the SQL optimizer works in Oracle by generating query plans using Explain and comparing performance to queries executed on Hive. Various query types including single relations, joins, aggregates, and subqueries are executed on both Oracle and Hive and their plans and performance are analyzed and compared to understand how each system optimizes queries and executes them efficiently.
The document discusses JDBC (Java Database Connectivity), which provides a standard interface for connecting to relational databases from Java applications. It describes fundamental JDBC concepts like establishing a connection, executing queries using Statement and PreparedStatement objects, processing result sets, and transaction management. The document also contrasts databases with file systems and provides JDBC driver names and URL formats for popular databases.
JDBC (Java Database Connectivity) provides APIs for Java programs to connect to databases. There are four types of JDBC drivers: Type 1 uses JDBC-ODBC bridge, Type 2 uses a native API, Type 3 is pure Java using a network protocol, and Type 4 is also pure Java using a native database protocol.
To connect to a database using JDBC, a program loads the appropriate JDBC driver, gets a connection, creates statements to execute SQL queries and updates, processes the result set, and closes resources. Prepared statements can be used for repetitive queries to improve performance over regular statements. Overall, JDBC allows Java applications to connect to databases in a standardized way
The document provides an overview of the Java Database Connectivity (JDBC) API. It discusses that JDBC allows Java applications to connect to relational databases and execute SQL statements. It describes the different types of JDBC drivers and the core JDBC classes like Connection, Statement, ResultSet, and their usage. The steps to connect to a database and execute queries using JDBC are outlined. Key concepts like processing result sets, handling errors, batch processing, stored procedures are also summarized.
This document provides information on Spring's enterprise data access features, including Data Access Objects (DAOs), data access templates, exception handling, and integration with ORM frameworks like Hibernate. It discusses how Spring provides DAO support classes, exception translation, and resource management to simplify data access. It also covers Spring's JDBC and Hibernate templates which provide a consistent interface and exception handling for data access code. The document shows how to configure datasources, JDBC templates, and Hibernate session factories in Spring.
JDBC is used to connect Java applications to databases. It uses drivers specific to each database type. The key steps are: 1) loading the driver, 2) defining the connection URL, 3) establishing a connection, 4) creating statements to execute queries or updates, 5) processing result sets, and 6) closing connections. Prepared statements are useful for queries executed multiple times to avoid recompilation. Transactions allow grouping statements that must all succeed or fail together to maintain database consistency.
JDBC (Java Database Connectivity) provides Java applications with access to most database systems via SQL. It defines a standard API for accessing databases in Java. The key classes and interfaces in JDBC include DriverManager, Connection, Statement, PreparedStatement, ResultSet, and DatabaseMetaData. JDBC applications use the DriverManager to obtain a Connection to a database, then execute SQL statements using Statement or PreparedStatement objects to return ResultSet objects containing query results.
This document provides an overview of Java Database Connectivity (JDBC) in 3 sentences or less:
JDBC allows Java programs to connect to and interact with various database systems and provides a standard API for querying and manipulating data in relational databases. The key components of JDBC include the DriverManager, Connection, Statement, and ResultSet objects, and connecting to a database typically involves 4 steps - loading a driver, opening a connection, executing SQL statements via a Statement object, and processing result sets. JDBC offers database independence and ease of administration along with the ability to access any database from Java applications.
The document discusses obtaining a connection to a database in Java using JDBC. It provides code examples of creating a database connection using the DriverManager class and Oracle's JDBC Thin driver. The code inserts a record into an EMP table for demonstration purposes. Best practices for database connectivity in a Java project are then covered, such as using the DAO pattern to separate data access logic from business logic. This improves testability, reusability and flexibility in switching database types.
EJB 3.0 Java Persistence with Oracle TopLinkBill Lyons
This document discusses using Oracle TopLink as a persistence framework with Java Persistence API (JPA) and EJB 3.0. It provides an overview of setting up a TopLink project in JDeveloper, generating entity objects and a session bean, and performing basic CRUD operations. The document demonstrates how to query, insert, update, and delete data using the TopLink APIs.
This document provides an overview of database connectivity in Java. It discusses how Java applications can connect to databases using the JDBC API. It describes the different types of JDBC drivers (types I-IV) and how they work. The key steps in a JDBC program are outlined, including loading a driver, establishing a connection, creating statements, executing queries, and processing result sets. Common SQL statements like SELECT, INSERT, UPDATE and DELETE are explained. Overall, the document serves as an introduction to using the JDBC API to connect Java applications to various database management systems.
Similar to Java Database Connectivity with JDBC.pptx (20)
Supermarket Management System Project Report.pdfKamal Acharya
Supermarket management is a stand-alone J2EE using Eclipse Juno program.
This project contains all the necessary required information about maintaining
the supermarket billing system.
The core idea of this project to minimize the paper work and centralize the
data. Here all the communication is taken in secure manner. That is, in this
application the information will be stored in client itself. For further security the
data base is stored in the back-end oracle and so no intruders can access it.
Blood finder application project report (1).pdfKamal Acharya
Blood Finder is an emergency time app where a user can search for the blood banks as
well as the registered blood donors around Mumbai. This application also provide an
opportunity for the user of this application to become a registered donor for this user have
to enroll for the donor request from the application itself. If the admin wish to make user
a registered donor, with some of the formalities with the organization it can be done.
Specialization of this application is that the user will not have to register on sign-in for
searching the blood banks and blood donors it can be just done by installing the
application to the mobile.
The purpose of making this application is to save the user’s time for searching blood of
needed blood group during the time of the emergency.
This is an android application developed in Java and XML with the connectivity of
SQLite database. This application will provide most of basic functionality required for an
emergency time application. All the details of Blood banks and Blood donors are stored
in the database i.e. SQLite.
This application allowed the user to get all the information regarding blood banks and
blood donors such as Name, Number, Address, Blood Group, rather than searching it on
the different websites and wasting the precious time. This application is effective and
user friendly.
Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...IJCNCJournal
Paper Title
Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation with Hybrid Beam Forming Power Transfer in WSN-IoT Applications
Authors
Reginald Jude Sixtus J and Tamilarasi Muthu, Puducherry Technological University, India
Abstract
Non-Orthogonal Multiple Access (NOMA) helps to overcome various difficulties in future technology wireless communications. NOMA, when utilized with millimeter wave multiple-input multiple-output (MIMO) systems, channel estimation becomes extremely difficult. For reaping the benefits of the NOMA and mm-Wave combination, effective channel estimation is required. In this paper, we propose an enhanced particle swarm optimization based long short-term memory estimator network (PSOLSTMEstNet), which is a neural network model that can be employed to forecast the bandwidth required in the mm-Wave MIMO network. The prime advantage of the LSTM is that it has the capability of dynamically adapting to the functioning pattern of fluctuating channel state. The LSTM stage with adaptive coding and modulation enhances the BER.PSO algorithm is employed to optimize input weights of LSTM network. The modified algorithm splits the power by channel condition of every single user. Participants will be first sorted into distinct groups depending upon respective channel conditions, using a hybrid beamforming approach. The network characteristics are fine-estimated using PSO-LSTMEstNet after a rough approximation of channels parameters derived from the received data.
Keywords
Signal to Noise Ratio (SNR), Bit Error Rate (BER), mm-Wave, MIMO, NOMA, deep learning, optimization.
Volume URL: https://airccse.org/journal/ijc2022.html
Abstract URL:https://aircconline.com/abstract/ijcnc/v14n5/14522cnc05.html
Pdf URL: https://aircconline.com/ijcnc/V14N5/14522cnc05.pdf
#scopuspublication #scopusindexed #callforpapers #researchpapers #cfp #researchers #phdstudent #researchScholar #journalpaper #submission #journalsubmission #WBAN #requirements #tailoredtreatment #MACstrategy #enhancedefficiency #protrcal #computing #analysis #wirelessbodyareanetworks #wirelessnetworks
#adhocnetwork #VANETs #OLSRrouting #routing #MPR #nderesidualenergy #korea #cognitiveradionetworks #radionetworks #rendezvoussequence
Here's where you can reach us : ijcnc@airccse.org or ijcnc@aircconline.com
This study Examines the Effectiveness of Talent Procurement through the Imple...DharmaBanothu
In the world with high technology and fast
forward mindset recruiters are walking/showing interest
towards E-Recruitment. Present most of the HRs of
many companies are choosing E-Recruitment as the best
choice for recruitment. E-Recruitment is being done
through many online platforms like Linkedin, Naukri,
Instagram , Facebook etc. Now with high technology E-
Recruitment has gone through next level by using
Artificial Intelligence too.
Key Words : Talent Management, Talent Acquisition , E-
Recruitment , Artificial Intelligence Introduction
Effectiveness of Talent Acquisition through E-
Recruitment in this topic we will discuss about 4important
and interlinked topics which are
Determination of Equivalent Circuit parameters and performance characteristic...pvpriya2
Includes the testing of induction motor to draw the circle diagram of induction motor with step wise procedure and calculation for the same. Also explains the working and application of Induction generator
3. ECE
318
-
Programming
Principles
for
Engineers.
Introduction
DataBase Management System (DBMS)
● Mechanisms for storing and organizing data
● Access, store, modify data without concern for internal representation (information hiding)
Structured Query Language (SQL)
● Standard language used with relational databases to perform queries and manipulate data
Java DataBase Connectivity (JDBC)
● Java programs communicate with databases using JDBC
● JDBC driver implements interface to database
4. ECE
318
-
Programming
Principles
for
Engineers.
Relational database model
Relational database
● Logical representation of data, not necessarily the way the data is stored
● Table
○ Rows (entities), columns (attributes)
● Primary key (column or group of columns)
○ Unique value for each row
○ Not every table has a primary key
● SQL statement
○ Query (which data to select from table or tables)
12. ECE
318
-
Programming
Principles
for
Engineers.
SQL: SELECT * WHERE
Specify the selection criteria (predicates)
SELECT columnName1, columnName2, … FROM tableName WHERE criteria
SELECT title, editionNumber, copyright
FROM titles
WHERE copyright > 2000
14. ECE
318
-
Programming
Principles
for
Engineers.
WHERE clause
WHERE clause condition operators
<, >, <=, >=, =, <>, LIKE
LIKE (pattern matching)
wildcard characters % and _
% or * (zero or more characters no matter what they are)
_ or ? (single character no matter what it is)
• wildcard string surrounded by single quotes
17. ECE
318
-
Programming
Principles
for
Engineers.
ORDER BY clause
Optional ORDER BY clause
SELECT columnName1, columnName2, … FROM tableNameORDER BY column [ASC]
SELECT columnName1, columnName2, … FROM tableNameORDER BY column DESC
Note that ASC is default (thus optional)
ORDER BY multiple fields
ORDER BY column1 sortingOrder, column2 sortingOrder, …
Combine the WHERE and ORDER BY clauses
–
22. ECE
318
-
Programming
Principles
for
Engineers.
Joining: Merging data from multiple tables
Split related data into separate tables to avoid redundancy
Join the tables
Merge data from multiple tables into a single view
INNER JOIN
•SELECT columnName1, columnName2, …
FROM table1
INNER JOIN table2
ON table1.columnName = table2.column2Name
•SELECT firstName, lastName, isbn
FROM authors
INNER JOIN authorISBN
ON authors.authorID = authorISBN.authorID
ORDER BY lastName, firstName
28. ECE
318
-
Programming
Principles
for
Engineers.
Connection to and Querying a Database
Example: DisplayAuthors.java
Retrieves the entire authors table
Connection object manages connection between Java program and database
connection = DriverManager.getConnection (DATABASE_URL);
URL jdbc:db2j:books specifies communication protocol (jdbc), subprotocol (db2j), name of
database (books)
getConnection overloaded (one version can be used to supply account and password)
29. ECE
318
-
Programming
Principles
for
Engineers.
Connection to and Querying a Database
Example: DisplayAuthors.java
Retrieves the entire authors table
Displays the data in a JTextArea
Connection object manages connection between Java program and database
connection = DriverManager.getConnection (DATABASE_URL);
URL jdbc:db2j:books specifies communication protocol (jdbc), subprotocol (db2j), name of
database (books)
getConnection overloaded (one version can be used to supply account and password)
1 // Fig. 23.26: DisplayAuthors.java
2 // Displaying the contents of the authors table.
3
4 import java.awt.*;
5 import java.sql.*;
6 import java.util.*;
7 import javax.swing.*;
8
9 public class DisplayAuthors {
10
11 // JDBC driver name and database URL
12 static final String JDBC_DRIVER = "com.ibm.db2j.jdbc.DB2jDriver";
13 static final String DATABASE_URL = "jdbc:db2j:books";
14
15 // declare Connection and Statement for accessing
16 // and querying database
17 private Connection connection;
18 private Statement statement;
19
20 // constructor connects to database, queries database, processes
21 // results and displays results in window
22 public DisplayAuthors()
23 {
24 super( "Authors Table of Books Database" );
25
30. ECE
318
-
Programming
Principles
for
Engineers.
Connection to and Querying a Database
Example: DisplayAuthors.java
Retrieves the entire authors table
Displays the data in a JTextArea
Connection object manages connection between Java program and database
connection = DriverManager.getConnection (DATABASE_URL);
URL jdbc:db2j:books specifies communication protocol (jdbc), subprotocol (db2j), name of
database (books)
getConnection overloaded (one version can be used to supply account and password)
26 // connect to database books and query database
27 try {
28
29 // specify location of database on filesystem
30 System.setProperty( "db2j.system.home", "C:/Cloudscape_5.0" );
31
32 // load database driver class
33 Class.forName( JDBC_DRIVER );
34
35 // establish connection to database
36 connection = DriverManager.getConnection( DATABASE_URL );
37
38 // create Statement for querying database
39 statement = connection.createStatement();
40
41 // query database
42 ResultSet resultSet =
43 statement.executeQuery( "SELECT * FROM authors" );
44
45 // process query results
46 StringBuffer results = new StringBuffer();
47 ResultSetMetaData metaData = resultSet.getMetaData();
48 int numberOfColumns = metaData.getColumnCount();
49
31. ECE
318
-
Programming
Principles
for
Engineers.
Connection to and Querying a Database
Example: DisplayAuthors.java
Retrieves the entire authors table
Displays the data in a JTextArea
Connection object manages connection between Java program and database
connection = DriverManager.getConnection (DATABASE_URL);
URL jdbc:db2j:books specifies communication protocol (jdbc), subprotocol (db2j), name of
database (books)
getConnection overloaded (one version can be used to supply account and password)
50 for ( int i = 1; i <= numberOfColumns; i++ )
51 results.append( metaData.getColumnName( i ) + "t" );
52
53 results.append( "n" );
54
55 while ( resultSet.next() ) {
56
57 for ( int i = 1; i <= numberOfColumns; i++ )
58 results.append( resultSet.getObject( i ) + "t" );
59
60 results.append( "n" );
61 }
62
63 72 } // end try
73 75
32. ECE
318
-
Programming
Principles
for
Engineers.
Connection to and Querying a Database
Example: DisplayAuthors.java
Retrieves the entire authors table
Displays the data in a JTextArea
Connection object manages connection between Java program and database
connection = DriverManager.getConnection (DATABASE_URL);
URL jdbc:db2j:books specifies communication protocol (jdbc), subprotocol (db2j), name of
database (books)
getConnection overloaded (one version can be used to supply account and password)
catch ( SQLException sqlException ) {
76
77
78 // print exception message
79 System.exit( 1 );
80 }
81
82 // detect problems loading database driver
83 catch ( ClassNotFoundException classNotFound ) {
84
85 // print exception message
86
87 System.exit( 1 );
88 }
89
90 // ensure statement and connection are closed properly
91 finally {
92
93 try {
94 statement.close();
95 connection.close();
96 }
97
33. ECE
318
-
Programming
Principles
for
Engineers.
Connection to and Querying a Database
Example: DisplayAuthors.java
Retrieves the entire authors table
Displays the data in a JTextArea
Connection object manages connection between Java program and database
connection = DriverManager.getConnection (DATABASE_URL);
URL jdbc:db2j:books specifies communication protocol (jdbc), subprotocol (db2j), name of
database (books)
getConnection overloaded (one version can be used to supply account and password)
98 // handle exceptions closing statement and connection
99 catch ( SQLException sqlException ) {
100 JOptionPane.showMessageDialog( null,
101 sqlException.getMessage(), "Database Error",
102 JOptionPane.ERROR_MESSAGE );
103
104 System.exit( 1 );
105 }
106 }
107
108 } // end DisplayAuthors constructor
109
110 // launch the application
111 public static void main( String args[] )
112 {
113 DisplayAuthors window = new DisplayAuthors();
114 window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
115 }
116
117 } // end class DisplayAuthors
34. ECE
318
-
Programming
Principles
for
Engineers.
Connection to and Querying a Database
Example: DisplayAuthors.java
Retrieves the entire authors table
Displays the data in a JTextArea
Connection object manages connection between Java program and database
connection = DriverManager.getConnection (DATABASE_URL);
URL jdbc:db2j:books specifies communication protocol (jdbc), subprotocol (db2j), name of
database (books)
getConnection overloaded (one version can be used to supply account and password)
98 // handle exceptions closing statement and connection
99 catch ( SQLException sqlException ) {
100 JOptionPane.showMessageDialog( null,
101 sqlException.getMessage(), "Database Error",
102 JOptionPane.ERROR_MESSAGE );
103
104 System.exit( 1 );
105 }
106 }
107
108 } // end DisplayAuthors constructor
109
110 // launch the application
111 public static void main( String args[] )
112 {
113 DisplayAuthors window = new DisplayAuthors();
114 window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
115 }
116
117 } // end class DisplayAuthors