#1
This guide shows how to perform basic CRUD operations using Apache Derby as the database and Spring Boot as the backend framework.

1. Add Dependencies

In pom.xml:
<dependency>
  <groupId>org.apache.derby</groupId>
  <artifactId>derby</artifactId>
  <scope>runtime</scope>
</dependency>

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

2. Configure Derby

In application.properties:
spring.datasource.url=jdbc:derby:memory:demoDB;create=true
spring.datasource.driver-class-name=org.apache.derby.jdbc.EmbeddedDriver
spring.jpa.hibernate.ddl-auto=update

This runs Derby in embedded in-memory mode.

3. Create Entity

import jakarta.persistence.*;

@Entity
public class Book {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String title;
    private String author;

    // getters and setters
}

4. Repository

import org.springframework.data.jpa.repository.JpaRepository;

public interface BookRepository extends JpaRepository<Book, Long> {
}

5. REST Controller

import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/books")
public class BookController {
    private final BookRepository repo;

    public BookController(BookRepository repo) {
        this.repo = repo;
    }

    @PostMapping
    public Book create(@RequestBody Book book) {
        return repo.save(book);
    }

    @GetMapping
    public List<Book> readAll() {
        return repo.findAll();
    }

    @GetMapping("/{id}")
    public Book readOne(@PathVariable Long id) {
        return repo.findById(id).orElse(null);
    }

    @PutMapping("/{id}")
    public Book update(@PathVariable Long id, @RequestBody Book book) {
        book.setId(id);
        return repo.save(book);
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable Long id) {
        repo.deleteById(id);
    }
}

6. Test the CRUD

Run Spring Boot:
mvn spring-boot:run
Examples:
# Create
curl -X POST http://localhost:8080/books -H "Content-Type: application/json" -d '{"title":"Derby Basics","author":"Alice"}'

# Read
curl http://localhost:8080/books

# Update
curl -X PUT http://localhost:8080/books/1 -H "Content-Type: application/json" -d '{"title":"Derby Advanced","author":"Alice"}'

# Delete
curl -X DELETE http://localhost:8080/books/1

image quote pre code