Back to feed
Renewal·서른의 생활코딩

Following Toby 3.1 in Spring Boot — Chapter 1: Objects and Dependencies - 1.1 The Dreadful DAO

NS
normalstory
cover image

Following Toby 3.1 in Spring Boot — Chapter 1 Objects and Dependencies - 1.1 The Dreadful DAO 


0. Development environment 

- OS : mac

- STS : 4.0.1

- MySQL : Server version: 8.0.13 Homebrew

- Framework : for now, just a plain jar so it runs with as few dependencies as possible.


Related links: 

- Spring users group (homepage):     http://www.ksug.org/

- Spring users group Q&A:     https://groups.google.com/forum/#!topic/ksug/13vB4tCFqrI

- 2017 Spring Camp:                       https://www.youtube.com/playlist?list=PLdHtZnJh1KdZ6NDO9zc9hF4tONDLTSEUV




Chapter 1. Objects and Dependencies 

1.1 The Dreadful DAO

The first example is a DAO test wired up via JDBC. Dubbed 'the dreadful DAO.'

Simple example... but since some time has passed since publication, I couldn't just follow along. The MySQL version changes meant I had to tweak SSL and friends, and the older blog posts I found on Google didn't match the new version either. I kept hitting walls.

One lesson here: don't blindly follow a blog just because it seems to fit you. Compare several posts, verify up-front, make sure you understand why, then run it in your own way. If you just barrel ahead, fixing settings and environments later is a pain. Sure, you learn something in the process... but most people seem to give up along the way.




01-1. Rough process

     1. Install MySQL: I already wrote about this — linking instead~ 

2. Create a project in STS: I just used a plain Java project.

3. Register the MySQL jar: select the project you created, right-click for Build Path.

4. Under the src folder, create your own package and folder names, and create classes following the book. This first example has two class files. 

- The DAO that opens a DB connection via JDBC

- The JavaBean that includes main() and runs the example via the DAO(* <-- explained in the summary below)


01-2. The four issues I hit right from the start:


0. JDBC Connection comparison between MySQL and ORACLE, and basic JDBC theory

-> Understanding the Java Data Access Layer and accessing data via Spring JDBC : a great post, really well-organized! 

-> BE - Java DataBase Connectivity : also excellent! There are so many generous devs out there ;D


1. ESTABLISHING SSL CONNECTION WITHOUT SERVER'S IDENTITY VERIFICATION IS NOT RECOMMENDED.

->  The JDBC useSSL=false option


2.  mysql_native_password to caching_sha2_password.

-> ALTER USER 'student'@'localhost' IDENTIFIED WITH mysql_native_password BY 'pass123';


3. Unknown system variable querycachesize

->  The jar added via STS build path didn't match my local version  

          : this happened because I was following old blog examples.


4. The server time zone value 'KST' is unrecognized or represents more than one time zone 

->  An issue where mysql-connector-java versions after 5.1.X don't recognize the KST time zone 



01-3. Result of the first example.

1) UserDao.class : reflects all the issues above.

2) User.class

3) The project export file. It has no dependencies, so if your dev environment matches it should run right away. (Well... matching the dev environment is always the hardest part.)

(1) Create the table in MySQL.

- create table users(id varchar(10) primary key, name varchar(20) not null, password varchar(10) not null);

- ALTER the_table_name_used_in_example 'the_ID_running_the_example'@'localhost' IDENTIFIED WITH mysql_native_password BY 'MySQL_password';


(2) import > Existing Projects into Workspace.

- Example project  :  

study_spring190217.zip
Download




01. Key 'brain-take' from the 'Dreadful DAO' chapter (Footnote: my personal take — the key points as I (think I) understand them.)

1. Lower school  

1) Spring is an application framework

(1) It provides a template and standards for how the objects composing an application are created and behave. 

(2) Java is valued most as a language because it enables object-oriented programming.

(3) Spring runtime engine = Spring container = application context — same thing.

(4) Can be registered and used as a service or servlet in a web module. 

(5) Its hallmark shared programming models are IoC/DI, service abstraction, and AOP.


2) What Spring cares about most are objects

You need to understand the object lifecycle (designing the unit of objects in the application > creating objects > establishing relationships with other objects > using them > letting them die).


3) A DAO (Data Access Object) is an object dedicated to querying or manipulating data via the DB.

(1) Acquire a Connection for the DB. 

(2) Build a Statement or PreparedStatement carrying the SQL.

(3) Execute the built Statement.

(4) For queries, receive the execution result as a ResultSet and copy it into an object that holds the info (in our case User.class).

(5) Always close() resources like Connection, Statement, and ResultSet when done.

(6) Exceptions raised by the JDBC API should either be handled here or thrown out of the method.  


4) JavaBean — an object created following these two conventions. 

(1) Default constructor: a JavaBean must have a no-argument default constructor because tools and frameworks create objects via reflection. 

(2) Properties: named attributes exposed by the bean, modifiable or queryable through setter methods (starting with 'set') and getter methods (starting with 'get'). 

2. Upper school

What are the problems with the UserDao class that works correctly — and even faithfully? Studying Spring means seeking answers to exactly those questions. 





Next up is 1.2 Separating the DAO  ;D


This English version was translated by Claude.

zipstudy_spring190217.zip
친절한 찰쓰씨
Written by
친절한 찰쓰씨

Pleasant Charles — UI/UX researcher at AIT. Keeping notes on design, planning, and slow days here since 2010.

More on the author's page

Keep reading

Renewal

Steadily, for the long haul, without burning out

Mar 31, 2026·9 min
Renewal

Tech-life balance

Feb 7, 2026·3 min
Renewal

Humanality, by Park Jeong-ryeol

Feb 7, 2026·11 min