Concurrent Collections and Maps-OCP Oracle Certified Professional

The CopyOnWriteArraySet Class – Concurrency: Part II

The CopyOnWriteArraySet<E> Class The CopyOnWriteArraySet class implements the java.util.Set interface (§15.4, p. 804). It does not implement any additional methods. Internally it uses a CopyOnWriteArrayList, and therefore shares the same basic properties with the list, except that, being a set, it does not allow duplicates and its elements have no ordering. Example 23.21 illustrates the

Introduction to Relational Databases – Database Connectivity

24.1 Introduction to Relational Databases Relational databases are based on the relational model that provides a standardized way to represent and query data. The data is stored in tables and queried using a query language. Relational Tables Relational databases store information in tables. Each table is designed to represent a business entity that applications need

Basic SQL Statements – Database Connectivity

Basic SQL Statements Structured Query Language (SQL) is used to perform relational database operations. Despite the existence of an ANSI (American National Standards Institute) SQL standard, different database providers may provide SQL implementations that are not exactly the same and may contain nuanced differences and proprietary additions. SQL statements can be logically grouped into a

Basic SQL Statements 2 – Database Connectivity

The UPDATE Statement The UPDATE statement can be used to update specific rows in a table. In other words, this statement modifies zero or more rows in the table: Click here to view code image UPDATEtable_name SETcolumn_name_value_pairs WHERErow_filter; where column_name_value_pairs in the SET clause is a comma-delimited list of pairs of column names and values: Click here

Introduction to JDBC – Database Connectivity

24.2 Introduction to JDBC The Java Database Connectivity (JDBC) protocol provides database interaction capabilities for Java programs. The JDBC specification is not database provider specific, allowing Java programs to interact with any database. The JDBC API is defined in the java.sql package. It comprises a number of interfaces that Java programs use to represent database

Establishing a Database Connection – Database Connectivity

24.3 Establishing a Database Connection Interaction between the application and the database is in the context of a connection. Database connections are represented by the java.sql.Connection interface. JDBC drivers provide database-specific implementations of this interface. The class java.sql.DriverManager provides the overloaded factory method get-Connection() that initializes and returns a database Connection object. Click here to

Getting a Database Connection – Database Connectivity

Getting a Database Connection To create a connection to a Derby database, the following code can be emulated: Click here to view code image String jdbcURL  = “jdbc:derby:localhost:1521:musicDB”;String username = “joe”;String password = “welcome1”;try (Connection connection = DriverManager.getConnection(jdbcURL,                                                         username, password)) {  /* use the connection. */} catch (SQLException e) {  e.printStackTrace();} A portion of the

Creating and Executing SQL Statements – Database Connectivity

24.4 Creating and Executing SQL Statements The JDBC API defines three interfaces that represent SQL statements: The result of executing a SELECT statement is a table of rows represented by the following interface: All statements are created using a previously initialized JDBC connection object. A statement is created using one of the methods of the

SQL Injection – Database Connectivity

SQL Injection Passing the SQL operation as a string in the execute method presents the risk of a SQL injection, as malicious SQL code can be injected into the query string. Assume that there is a basic statement that queries a table, where the query is dependent on a value: Click here to view code