I'd like to preface that I'm somewhat of a novice looking for advice as I'm trying to build good habits.
The application I'm developing right now is a heavily integrated database application. As I develop and explore and implement the requirements for each of my entities, I'm finding that my classes are just exploding with code to run queries in different ways on each of the entities.
While it might not be a bad thing right now, in terms of maintenance, I foresee my application being a nightmare to debug and update.
Do any JDBC experts out there have any suggestions for design patters that would help slim down the boiler-plate type code for handling all of these queries? Or should I stray from that completely and use JPA?
I've tried to implement JPA in the past, but have had trouble with complex entity relationships. Should I just read a JPA book and go from there?
Also, JPA is thought to be better suited for more sophisticated applications by many developers. But, JDBC is considered the preferable alternative if an application will use a simple database and we don't plan to migrate it to a different database vendor.
JDBC is a low level standard for interaction with databases. JPA is higher level standard for the same purpose. JPA allows you to use an object model in your application which can make your life much easier. JDBC allows you to do more things with the Database directly, but it requires more attention.
Explicitly closing your JDBC resources when done with themResultSets, Statements, and Connections should be explicitly closed by the application when they are no longer needed. This allows the resources to be cleaned up in the most efficient way possible and can increase performance.
JPA can be a good long-term solution. But if you prefer to stay closer to plain SQL, you can consider other options like Spring Framework's JDBC support.
Note that, you don't need to use other spring framework components link DI, MVC etc to be able to use Spring JDBC. It is quiet easy to use without other parts spring framework. When using spring jdbc, you don't need to do following tasks in your code:
What you need to do is:
Another benefit of spring-jdbc is that it replaces JDBC checked exceptions with unchecked exceptions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With