How To Strategy Java, Databases, and SQL [Video]

We need to save our thumbnail knowledge to a database in order that we will render our photos to a pleasant HTML gallery web page and end the proof of idea for our Google Photos clone

Which database ought to we use and why? Which Java database API? What database instruments will make our lives simpler alongside the best way? Discover out on this episode of Marco Codes!

What’s within the Video

00:00 Intro 

We’ll cowl what the plan is for this episode: so as to add database capabilities to our Google Photographs clone, which presently solely works with information, however would not retailer their metadata in a database desk.

00:52 The place We Left Off

Earlier than leaping straight into implementing database and ORM options, we’ll do a fast code recap of the earlier episodes, to remind ourselves how the picture scanning and conversion course of presently works.

01:46 Setup 

Every time we need to do one thing with databases and Java, we want a few (on this case) Maven dependencies. Extra particularly we need to be certain that so as to add the H2 database to our venture, which we’ll use for manufacturing, not only for testing! We’ll additionally add the HikariCP connection pool to it – one thing I do by default in each venture and which is normally carried out routinely by frameworks like Spring Boot.

04:38 Writing a Database Schema 

Right here, I current my present method when doing Java database work: ensuring the database schema is hand-written, pondering by desk names, column names, sorts, and so on. Therefore, we’ll begin writing a schema.sql file for our new “media” desk throughout this part.

10:08 Making a DataSource

Having created the schema, we’ll have to create a DataSource subsequent. As we’re utilizing HikariCP, we’ll comply with its documentation pages to arrange the DataSource. We’ll additionally be certain that the schema.sql file written earlier will get routinely executed every time we run our utility.

12:46 Saving Thumbnail Information 

It is lastly time to not simply render thumbnail information on disk, but in addition save details about the generated thumbnails and unique photos in our brand-new database desk! We’ll use plain JDBC to try this and speak about its benefits and drawbacks.

14:00 Refactoring Maneuver 

Generally you simply have to _see_ sure issues which are very exhausting to elucidate in phrases. To wash up our program, we should change a few methodology signatures and transfer parameters up and down all through the file.

16:21 Extracting Picture Creation Dates 

In the mean time, we do not correctly detect the picture creation date from its metadata. We’ll speak about the right way to implement this sooner or later and why we’ll keep on with the file creation date for now.

17:10 Avoiding Duplication 

We’ll additionally have to deal with duplicates. If we re-run our program a number of instances, we do not need to retailer the picture metadata a number of instances in our tables. Let’s repair this right here.

19:04 Inspecting H2 File DBs 

In case you do not know the right way to entry H2 file databases, we’ll spend a while exhibiting you the way to try this from inside IntelliJ IDEA and its database instrument window.

21:23 Rendering HTML Output 

Final however not least, we’ll have to render all the knowledge from our database to a pleasant, little HTML web page, so we will really browse our thumbnails! As a bonus level, this would be the easiest and doubtless dirtiest implementation of such an HTML web page you have seen for some time – but it surely works!

30:30 What’s Subsequent?

Did you want what you noticed? Which function ought to we implement subsequent? Let me know!

Video