Database application of Java, JDBC and JPA

I would like to introduce that I am looking for a novice for advice because I am trying to establish good habits

The application I am developing now is a highly integrated database application When I developed, explored and implemented the requirements of each entity, I found that my class just used code to explode and run queries on each entity in different ways

Although this may not be a bad thing, in terms of maintenance, I foresee that my application is a nightmare to debug and update

Any JDBC expert has any suggestions on the design pattern, which will help reduce the boiler board type code to handle all these queries? Or should I deviate completely from this and use JPA?

In the past, I tried to implement JPA, but I had trouble with complex entity relationships Should I read a JPA book from there?

Solution

JPA can be a good long - term solution However, if you want to stay closer to pure SQL, you can consider other options, such as spring framework's JDBC support

Please note that you do not need to use other spring frame components to link Di, MVC, etc. to use spring JDBC No other parts, spring frame, quiet and easy to use When using spring JDBC, you do not need to perform the following tasks in your code:

>Open connection. > Prepare and execute statements. > Set the loop traversal result (if any). > Handle any exceptions. > Processing transactions. > Close connections, statements, and result sets

What you need to do is:

>Define connection parameters (once) > specify the SQL statement (for each query) > declare parameters and provide parameter values (when using preparation statements) > do the work of each iteration (the spring performs result set traversal and only needs to provide logic to act on a single row)

Another advantage of spring JDBC is that it replaces JDBC checked exceptions with unchecked exceptions

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>