Guide3:Accessing Relational Data using JDBC with Spring

This guide walks you through the process of accessing relational data with Spring.

You will build an application that uses Spring’s JdbcTemplate to access data stored in a relational database.

1 创建新项目

在这里插入图片描述

2 创建实体类

The simple data access logic you will work with manages the first and last names of customers. To represent this data at the application level, create a Customer class.

package com.example.relationaldataaccess;

public class Customer {
   
    private long id;
    private String firstName, lastName;

    public Customer(long id, String firstName, String lastName) {
   
        this.id = id;
        this.firstName = firstName;
        this.lastName = lastName;
    }

    @Override
    public String toString() {
   
        return String.format(
                "Customer[id=%d, firstName='%s', lastName='%s']",
                id, firstName, lastName);
    }

    // getters & setters omitted for brevity
}

3 存储和检索数据

Spring provides a template class called JdbcTemplate that makes it easy to work with SQL relational databases and JDBC.
Most JDBC code is mired in resource acquisition, connection management, exception handing, and general error checking that is wholly unrelated to what the code is meant to achieve.
The JdbcTemplate takes care of all of that for you. All y

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值