O'Reilly logo

The Cucumber for Java Book by Seb Rose, Matt Wynne, Aslak Hellesoy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Refactoring to Use a Database

In our current system, the balance of the single account is stored in a file and read and written by the BalanceStore class. In our new design, we will make the Account responsible for reading the balance straight out of a database instead. It’s refactoring time again!

Creating the Database

Once you have installed MySQL[47] you will need to create a database and user. This can be done simply, using the setup-bank.sql script:

databases/00/setup-bank.sql
 
CREATE​ ​DATABASE​ bank;
 
CREATE​ USER ​'teller'​@​'localhost'​ IDENTIFIED ​BY​ ​'password'​;
 
GRANT ALL ​ON​ bank.* TO ​'teller'​@​'localhost'​;

As you can see, this script creates a database called bank. It then adds a user teller with password password and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required