Question
In some of my projects I used SQL code, this is nothing special. But I rethought this strategy. I was looking for SO to separate code and SQL.
I found one answer that I liked, collecting all your SQL statements in a properties file. I think it is beautiful and clean. But what if you want to insert variables.
Another solution I found was to use DAO objects. For example, I create the MYSQLFactory class in the following ways: addCustomer (client client), deleteCustomer (int CustomerId), etc. You would centralize your SQL code. Still will not call it divided.
Is there a better way to do this without using ORM like Hibernate. The more I read, the more I become convinced that there is no clear way with JAVA.
Source sources
Java - saving SQL statements in an external file
Separating SQL from Java Code
Update
Thanks for the great answers. I was just wondering. @ Gilbert, I think this is a great solution. In fact, I already used your solution at a time, so thanks for that. :)
Sometimes I just like to research new problems with specific problems.
source share