Principles of Apache Derby database engine and embedded JDBC -driven technology

Apache Derby is a Java -based embedded relational database engine.It is designed for lightweight applications and embedded systems, which can run without an independent database server.Derby provides standard JDBC interfaces, so that developers can easily use database functions in Java applications. Derby's technology implementation principle involves the following key aspects: 1. Embedded database engine: Derby uses an embedded mode deployment, that is, it can be directly embedded in the application and operates as a whole with the application.Such a design makes Derby's deployment and use very flexible and does not require independent database servers.DERBY's database file is stored in the file system and can be accessed through the file path. 2. Memory database: Derby can run in the form of memory database, which means that data can temporarily exist in memory without having to write a disk.The memory database has a very fast read and write speed, suitable for application scenarios that require high performance. 3. JDBC driver: Derby provides a JDBC drive called Derby Embedded Drive, which is used to connect and operate the Derby database in Java applications.By using the JDBC drive, developers can use standard JDBC APIs to perform database operations, such as creating tables, inserting data, updating data, and query data. Below is an example of using Apache Derby's embedded database engine and JDBC -driven Java code: First of all, you need to download and import Derby's JDBC driver library.You can download the corresponding jar files from Apache Derby's official website and add it to the construction path of the Java project. import java.sql.*; public class DerbyExample { public static void main(String[] args) { try { // Connect to Derby database Connection connection = DriverManager.getConnection("jdbc:derby:sampleDB;create=true"); // Create a table Statement statement = connection.createStatement(); statement.executeUpdate("CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(50))"); // Insert data statement.executeUpdate("INSERT INTO users VALUES (1, 'John')"); statement.executeUpdate("INSERT INTO users VALUES (2, 'Mary')"); statement.executeUpdate("INSERT INTO users VALUES (3, 'David')"); // Query data ResultSet resultSet = statement.executeQuery("SELECT * FROM users"); while (resultSet.next()) { int id = resultSet.getInt("id"); String name = resultSet.getString("name"); System.out.println("ID: " + id + ", Name: " + name); } // Close connection and resources resultSet.close(); statement.close(); connection.close(); } catch (SQLException e) { e.printStackTrace(); } } } The above code demonstrates how to connect to the Derby database, create tables, insert data, and query data.In this example, the database will be created in a folder called "Sampledb" in the current directory. Summary: The Apache Derby database engine adopts an embedded deployment mode, which can easily integrate with Java applications.Through the JDBC drive, developers can use the standard JDBC API to connect and operate the Derby database.Memory database and embedded deployment make Derby have the characteristics of fast, flexible and easy to use, and is suitable for various scale application systems.