Back to articles
SQL Directly in Java — I built a lightweight Java framework for Japan's "SI" projects (third attempt in 10 years) #10

SQL Directly in Java — I built a lightweight Java framework for Japan's "SI" projects (third attempt in 10 years) #10

via Dev.tosugaiketadao

Introduction Over the years I've written SQL in XML files, embedded it in entity classes, and built it inline in Java. Each approach has trade-offs, but two pain points kept recurring: Dynamic search conditions — the more conditions you add, the harder the XML <if> tags become to read Batch processing performance — when INSERT/UPDATE runs inside a loop, you start worrying about PreparedStatement overhead SIcore's answer is two SQL-building classes tailored to each use case: SqlBuilder — assembles SQL dynamically (primarily for web service search queries) SqlConst — defines SQL statically (primarily for batch processing) This article introduces both and explains when to use each. What This Article Covers The friction of XML-based SQL management SqlBuilder — how dynamic SQL assembly works SqlConst — static SQL with type-safe binding PreparedStatement caching with SqlConst Combining with Java Text Blocks ( """ ) The Problem with XML-Based SQL O/R mappers like MyBatis write SQL in XML file

Continue reading on Dev.to

Opens in a new tab

Read Full Article
2 views

Related Articles